2

I want save Sprite in storage and load Sprite Image. currently storage save work well. but load not working :(

save Code :

private StorageReference storageReference;
storageReference = FirebaseStorage.DefaultInstance.GetReferenceFromUrl("my storage URL");

    public void SaveShopImage(string fileName, Sprite sprite)
{
    Texture2D ShopTexture = textureFromSprite(sprite);
    var ImageByte = ShopTexture.GetRawTextureData();
    StorageReference rivers_ref = storageReference.Child("Filename");

    rivers_ref.PutBytesAsync(ImageByte).ContinueWith((Task<StorageMetadata> task) =>
      {
          if (task.IsFaulted || task.IsCanceled)
          {
              Debug.Log(task.Exception.ToString());
          }
          else
          {
              Debug.Log("Finished uploading...");
          }          
      });
}    

it work well. but load script not working.. in UnityEditor Log output is only up to ("A"). ("B") will not be output and the following codes will not work either.

load Code :

    public void ReadShopImage(string ResourceName, Sprite spriteToSet)
{
    const long maxAllowedSize = 1 * 1024 * 1024;
    storageReference.Child("Filename").GetBytesAsync(maxAllowedSize).ContinueWith((Task<byte[]> task) => {
        if (task.IsFaulted || task.IsCanceled)
        {
            Debug.Log(task.Exception.ToString());
        }
        else
        {
            byte[] fileContents = task.Result;
            Debug.Log("A");

            Texture2D texture = new Texture2D(100, 100);
            texture.LoadImage(fileContents);
            Debug.Log("B");

            SaveToSprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
            Debug.Log("Finished downloading!");
        }
    });
}

Did I do something wrong? How can I set SpriteImage from FirebaseStorage or How can I save images useFirebaseDatabase?

Thank you for reading my question. Have a nice day.

======================================================= and i solved using ContinueWithOnMainThread:) How to download image from Firebase storage?

but sprite is not changing ha..

김락준
  • 21
  • 2

0 Answers0