Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity+Firebase

Discussion in 'Scripting' started by gaglabs, Sep 10, 2020.

  1. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    141
    So im looking for a way to retrieve all available images from Firebase Storage. So when the user uploads an image it gets sent to the storage bucket under Images/ followed by their ID. So its just a whole list of images.
    Image.jpg, Image1.jpg, etc.. But when i run this code

    Code (CSharp):
    1.  public void LoadAllImages(string _id)
    2.         {
    3.        
    4.             StorageReference fileRef = Storage.RootReference.Child(AppSettings.RootUserStorageKey).Child(_id).Child(AppSettings.UserFeedImage);
    5.          
    6.             const long maxAllowedSize = 1 * 1024 * 1024;
    7.             fileRef.GetBytesAsync(maxAllowedSize).ContinueWith((Task<byte[]> task) => {
    8.             if (task.IsFaulted || task.IsCanceled) {
    9.  
    10.                 Debug.Log(task.Exception.ToString());
    11.              
    12.             } else {
    13.  
    14.                 byte[] fileContents = task.Result;
    15.                 foreach(char _name in fileContents.ToString())
    16.                 {
    17.                     texture.Add(_name);
    18.                 }
    19.                 Debug.Log("Finished downloading!");
    20.             }
    21.             });
    22.          
    23.         }
    It returns as task.IsFaulted. Im assuming because i need to specify which file im trying to grab, but i don't want a specific one, i want them all so i can show an image gallery. Any help would be appreciated.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    9,035
    I think this is more a question about using the Firebase API than about Unity... you might have more luck checking their forums to see if they have tips for getting this. You might also check the Firebase API docs page because who knows, maybe there is sample code to do exactly what you're trying to do.
     
  3. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    141
    I did check the API on Firebase website and they provided nothing on this. To be honest a lot of the features i use in my app from Firebase aren't on their website. And the Firebase Forum on google groups is mainly for native integration. No body really has a good forum group for unity and firebase.
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,509
    https://firebase.google.com/docs/storage/unity/download-files#download_files

    From what I can see, you can't do what you want to do. It doesn't look like they have a way to pull everything easily as it all targets a file in some way or another.

    However, you might be able to do something with cloud functions. https://firebase.google.com/docs/storage/extend-with-functions, since it looks like the web, iOS, and Android api have a list call, you might be able to tap into that.

    The other option is to follow using storage and database together https://stackoverflow.com/questions...-all-files-in-cloud-storage-in-a-firebase-app.
     
  5. gaglabs

    gaglabs

    Joined:
    Oct 17, 2019
    Posts:
    141
    Hey Brath, yeah that's what i ended up doing. I made a child node of a users images under their UID which is under the parent node, UserImage. Then it gets all of them in a snapshot and populates to a list and then uses unity WebRequest. The issue i face now is that you cant reference the entire Storage in the child node parameters. So you have to uses the last like 20 letters and remove the .jpg from the end. That's the name of the Image. But Firebase wont let you use symbols so i then have to use the URL that points to my Storage and then re add the name.jpg to the end using foreach in my list. But, that's showing the image as blank. Working on fixing that now. Thanks for the help gentleman.
     
unityunity