Unity-Firebase-GetAllImages

148 views
Skip to first unread message

shawnre...@gmail.com

unread,
Sep 9, 2020, 10:13:24 PM9/9/20
to Firebase Google Group
Im trying to get all available images a user has in storage. I cant seem to find a solution to retireve all images located in the users storage. 

 public void LoadAllImages(string _id)
        {
           
            StorageReference fileRef = Storage.RootReference.Child(AppSettings.RootUserStorageKey).Child(_id).Child(AppSettings.UserFeedImage);
            
            const long maxAllowedSize = 1 * 1024 * 1024;
            fileRef.GetBytesAsync(maxAllowedSize).ContinueWith((Task<byte[]> task) => {
            if (task.IsFaulted || task.IsCanceled) {

                Debug.Log(task.Exception.ToString());
                
            } else {

                byte[] fileContents = task.Result;
                foreach(char _name in fileContents.ToString())
                {
                    texture.Add(_name);
                }
                Debug.Log("Finished downloading!");
            }
            });
            
        }

This returns an error under task.Exception.ToString() which i guess is expected casue im not giving it a file name to look for so it returns nothing becuase it wont get all files. 

martin...@google.com

unread,
Sep 21, 2020, 6:22:50 PM9/21/20
to Firebase Google Group
It's hard to tell what's going on without the underlying exception.

Note that on iOS and Android, you can list all the files. This feature has not been ported to C++ or Unity though, and although the team is aware of the delta between the native and games SDKs you can always file an issue here if you want to know when this gap is closed.

For what could be going wrong with your code:
  1. If your security rules are too strict, the client might not be able to access the node you're trying to reach.
  2. maxAllowedSize could be small for an image (for an uncompressed raw image, that's about 341x341 pixels). For testing, I like to use `long.MaxValue` -- but beware that this could cause your game to crash if you regularly load more images into memory than your phone or tablet has free memory  (iOS and Android will prefer to terminate your game rather than returning null on an allocation - even in C++).
Reply all
Reply to author
Forward
0 new messages