0

I want to provide a feature that user can review all images which are uploaded by them. In my firebase storage, it contains user's images in /$uid/image folder.

/$uid/image/imageA.png
/$uid/image/imageB.png
/$uid/image/imageC.png

However, i don't know how to get the reference of full users file. i tried the code below to download it, but I got a storage/object-not-found error code.

var imageRef = storageRef.child('UserImage/'+ user.uid + '/image');

i just want to get a list of image's download url in Json format. For example,

{$uid/image:[
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX1',
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX2',
  'https://firebasestorage.googleapis.com/v0/b/XXXXXXXXXXXXXXXXXXXX3'
]}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
king yau
  • 500
  • 1
  • 9
  • 28
  • There is currently no API to get all files in a folder from Firebase Storage. See http://stackoverflow.com/questions/37335102/how-to-get-an-array-with-all-pictures/37337436#37337436 – Frank van Puffelen Jun 09 '16 at 04:00

1 Answers1

0

First make sure you are not missing a "/" here:

var imageRef = storageRef.child('UserImage/'+ user.uid + 'image');
                                                    here ^

Also make sure you include the actual file at the end of the reference (/image.png), not the users subtree of images.

Use this function:

imageRef.getDownloadURL().then(function(url) {
    // Get the download URL for '<reference>'
    // store the url, do something with it
}).catch(function(error) {
    // Handle any errors
});

You could then add these to an array or whatever you please.

Reference: getDownloadURL()

theblindprophet
  • 7,767
  • 5
  • 37
  • 55
  • i have already use this, so i can catch the error then log the error code in console.. – king yau Jun 08 '16 at 13:40
  • Then grab the url thats passed into the success, and check to make sure your path is correct. I have edited my answer – theblindprophet Jun 08 '16 at 13:45
  • i got an error which is `storage/object-not-found`. Also, my path should be correct because it get all right if i try to use `UserImage/'+ user.uid + '/image/' + 'imageA.png'`. – king yau Jun 08 '16 at 13:51
  • @ theblindprophet actual file? Does it mean that i cannot download a folder from firebase? – king yau Jun 08 '16 at 14:04