RageAgainstThePixel / com.rest.firebase.storage

A non-official Firebase RESTful Storage Client for Unity (UPM)
MIT License
5 stars 1 forks source link
firebase firebase-storage openupm unity unity-asset unity-scripts unity3d upm upm-package upm-publisher

Firebase.Storage

Discord openupm

A non-official Firebase RESTful Storage Client for the Unity Game Engine.

Based on FirebaseStorage.net

All copyrights, trademarks, logos, and assets are the property of their respective owners.

Installing

Via Unity Package Manager and OpenUPM

scoped-registries

Via Unity Package Manager and Git url


Documentation

// Create a firebase authentication client
var firebaseClient = new FirebaseAuthenticationClient();

// Create a firebase storage client
var firebaseStorageClient = new FirebaseStorageClient(firebaseClient);

// Sign the user in
await firebaseClient.SignInWithEmailAndPasswordAsync(email, password);

// Get a reference to the resource using a path.
var resource = firebaseStorageClient.Resource("root/test.json");

var json = "{\"value\":\"42\"}";

string downloadUrl;

using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
    // Upload content to storage
    downloadUrl = await resource.UploadAsync(stream, new Progress<FirebaseStorageProgress>(progress => Debug.Log(progress.Percentage)));
}

// Get content public download url (doesn't require authentication)
var knownUrl = await resource.GetDownloadUrlAsync();

Assert.IsTrue(downloadUrl == knownUrl);

// Download content
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(knownUrl);
var responseData = await response.Content.ReadAsStringAsync();
Assert.IsTrue(responseData == json);

// Delete storage content
await resource.DeleteAsync();

Additional Packages