Cloud Storage
Cloud Storage is built for game developers who need to store and serve user-generated content, such as save games, photos or videos.
Developers use the Firebase SDKs for Cloud Storage to upload and download files directly from clients. If the network connection is poor, the client is able to retry the operation right where it left off, saving your users time and bandwidth.
The Firebase SDKs for Cloud Storage integrate seamlessly with Firebase Authentication to identify users, and Google provides a declarative security language that lets you set access controls on individual files or groups of files, so you can make files as public or private as you want.
Storage Reference
Your files are stored in a Google Cloud Storage bucket. The files in this bucket are presented in a hierarchical structure, just like the file system on your local hard disk. By creating a reference to a file, your game gains access to it. These references can then be used to upload or download data, get or update metadata or delete the file. A reference can either point to a specific file or to a higher level node in the hierarchy.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki49.png
Create a reference to upload, download, or delete a file, or to get or update its metadata. A reference can be thought of as a pointer to a file in the cloud. References are lightweight, so you can create as many as you need. They are also reusable for multiple operations.
References are created from the storage service on your Firebase game by calling one of three functions:
- Get Storage Reference to Root – reference to the highest level of your storage
- Get Storage Reference from Path – reference to the specified path from root
- Get Storage Reference from Url – URL of the form gs://<your-cloud-storage-bucket>.
You can create a reference to a location lower in the tree, say images/space.jpg, by using the child method on an existing reference.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki51.png
You can also use the Parent function to navigate up one level in our file hierarchy.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki52.png
Child and Parent can be chained together multiple times, as each returns a reference. The exception is the Parent of Root, which is an invalid Storage Reference.
Storage Path
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki55.png
For downloading or uploading files you need to provide location where file should be located on the iOS or Android device. You can do this using the following functions:
- Get Platform Storage Path – returns a path to the physical storage on a device
- Get Unreal Storage Path – returns a path to the main directory of Unreal filesystem on a device
- Get Save Game Storage Path - returns a path to the directory of Unreal Save Games on a device
Download File
Cloud Storage allows developers to quickly and easily download files from a Google Cloud Storage bucket provided and managed by Firebase.
To download a file, first create a Cloud Storage reference to the file you want to download.
You can create a reference by appending child paths to the storage root, or you can create a reference from an existing gs:// or https:// URL referencing an object in Cloud Storage.
Once you have a reference, you can download files from Cloud Storage in two ways:
- Generate an string URL representing the file online
- Download to an specific path on the device
If you already have download infrastructure based around URLs, or just want a URL to share, you can get the download URL for a file by calling the Firebase Storage Reference Get Download Url function on a storage reference.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki45.png
The Firebase Storage Reference Get File function downloads a file directly to a local device. Use this if your users want to have access to the file while offline or to share in a different app.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki46.png
Upload File
Cloud Storage allows developers to quickly and easily upload files to a Google Cloud Storage bucket provided and managed by Firebase.
To upload a file, first create a Cloud Storage reference to the location in Cloud Storage you want to upload the file to. You cannot upload data with a reference to the root of your Google Cloud Storage bucket. Your reference must point to a child URL. Once you have a reference, you can upload files to Cloud Storage.
You can upload local files on the devices, such as photos and videos from the camera or saved games, with the Firebase Storage Reference Put File function. You can also include metadata when you upload files.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki54.png
Delete File
Of course you can also delete files from Cloud Storage.
To delete a file, first create a reference to that file. Then call the Firebase Storage Reference Delete method on that reference.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki50.png
Monitor progress of Downloads/Uploads
Downloads/Uploads functions returns Storage Listener object to which you can bind OnProgressEvent and OnPausedEvent in order to monitor the progress of files tasks.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki47.png
Manage Downloads/Uploads
In addition to starting downloads/uploads, you can pause, resume, and cancel downloads/uploads using the Pause, Resume, and Cancel functions on Storage Controller.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki48.png
Get/Update Metadata
After uploading a file to Cloud Storage reference, you can also get and update the file metadata, for example to update the content type.
You can update file metadata at any time after the file upload completes by using the Firebase Storage Reference Update Metadata function. Only the properties specified in the metadata are updated, all others are left unmodified. You can delete writable metadata properties by passing the empty string.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki58.png
File metadata contains common properties such as name, size, and content_type (often referred to as MIME type) in addition to some less common ones like content_disposition and time_created. This metadata can be retrieved from a Cloud Storage reference using the Firebase Storage Reference Get Metadata function.
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki56.png
https://gamednastudio.com/plugins/images/UltimateMobileKit/Wiki57.png