-
Notifications
You must be signed in to change notification settings - Fork 79
Storage 2.0
Firebase Cloud Storage can be used for storing large amounts of data that your app may use, whether it's user specific, or accessed everywhere. This plugin's storage API allows you to access all of this.
Author's note: this page only works for the 4.x version of the plugin. Please see Storage for details on how to use storage for Godot 3.x.
Firebase.Storage
This class is used globally, and is responsible for handling data requests between your app and your Firebase project.
Functions | Descriptions |
---|---|
ref(file_path: String) -> StorageReference |
Creates a reference to a file/folder in your cloud storage. |
StorageReference
These kinds of objects act as a reference to files and folders in your cloud storage. They have functions that allow you to interact with the server-side files.
Properties | Descriptions |
---|---|
bucket: String |
The bucket that this StorageReference is in. |
full_path: String |
The path of the file relative to the storage bucket. |
file_name: String |
The name of the file, including the extension. |
parent: StorageReference |
The parent of this StorageReference . If said StorageReference is the root, then the parent is null . |
root: StorageReference |
The root of this StorageReference . |
storage: FirebaseStorage |
The global class that handles all http requests on behalf of the StorageReference . |
Functions | Descriptions |
---|---|
child(file_path: String) -> StorageReference |
Returns a reference relative to file_path . |
put_data(data: PackedByteArray, metadata := {}) -> Variant |
Uploads the raw data to storage, along with metadata . Returns a Variant containing relevant information. |
put_string(data: String, metadata := {}) -> Variant |
Like put_data() , but with a String instead of a packed array of bytes. |
put_file(file_path: String, metadata := {}) -> Variant |
Like put_data() , but with a file_path that will have its referencing file data passed into storage. |
get_data() -> Variant |
Requests data from storage. The data is automatically returned as a PackedByteArray. |
get_string() -> String |
Like get_data() , but the data will be returned in the form of a string. |
get_download_url() -> Variant |
Requests a URL that points to the file. The result will be the returned value. |
get_metadata() -> Variant |
Requests the file's metadata. The metadata will be the returned value. |
update_metadata(metadata: Dictionary) -> Variant |
Updates the file's metadata. Any entry that's null will be deleted from storage. |
list() -> Variant |
Requests the list of folders and/or files that is under the referenced folder. Returned value is an Array. |
list_all() -> Variant |
Like list() , but includes any sub-folders' contents as well. |
delete() -> bool |
Deletes the file from storage. Returns true or false depending on success of deletion operation. |
var result = await Firebase.Storage.ref(storage_reference).put_file(local file)
This will upload a local file into Storage for later use
var result = await Firebase.Storage.ref("Firebasetester/upload/icon.png").put_file("res://icon.png")
var result = await Firebase.Storage.ref(storage_reference).put_string(String, {metadata})
This will upload a string for later use
var result = await Firebase.Storage.ref("Firebasetester/upload/junkdata").put_string("Test", {})
var download_url = await Firebase.Storage.ref(storage_reference).get_download_url()
This will get the download URL and display it in the console
var result = await Firebase.Storage.ref("Firebasetester/upload/icon.png").get_download_url()
print(result)
var result = await Firebase.Storage.ref(storage_reference).get_metadata()
This will get download the metadata for an object in storage and print it to the console
var result = await Firebase.Storage.ref("Firebasetester/upload/icon.png").get_metadata()
print(result)
var did_delete = Firebase.Storage.ref(storage_reference).delete()
This will delete an object in storage
var did_delete = await Firebase.Storage.ref("Firebasetester/upload/icon.png").delete()
var all_objects = await Firebase.Storage.ref(storage_reference).list_all()
This will list all objects in storage and print it to the console
var all_objects = await Firebase.Storage.ref("Firebasetester").list_all()
print(all_objects)