-1

I'm doing an app to test firebase-storage and when i try to get a random element from the storage no idea how to get de amount of elements on the folder

Is a JS app to display random images from a firebase storage

var randomIndex = Math.floor(Math.random() * storage.length);

I expect a random number from 0 to max elements on the storage

Radega
  • 3
  • 2

1 Answers1

0

You can try to list objects in a bucket using a server SDK, but this won't scale very well when the number of objects in the bucket becomes large. There is currently no list API for client SDKs.

Cloud Storage doesn't provide a simple way to count the number of objects in it. You should be using a database to track this instead.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • there actually **is** a method to list objects since [version 6.1](https://firebase.google.com/support/release-notes/js) in the client-side JavaScript SDK. I updated my answer here: https://stackoverflow.com/questions/37335102/how-to-get-a-list-of-all-files-in-cloud-storage-in-a-firebase-app to point that out too. – Frank van Puffelen Jun 14 '19 at 14:11
  • To be fair, they accidentally released that API before it was supposed to be released, and without documenting it. :-) – Doug Stevenson Jun 14 '19 at 14:19
  • Yup, waiting for both the other platforms and documentation too. :) – Frank van Puffelen Jun 14 '19 at 14:39