I’m try to apply Google Cloud Vision to files in my Firebase Cloud Storage using Firebase Cloud Functions.
The storage structure is bucket > images > userID > image. There are multiple users and they have multiple images in their folder. I want to be able to map/forEach the userID and then map/forEach the images. I am struggling to figure out how to go about this.
I have tried: List Objects In a Bucket but its not working, probably because its for GCP rather than Firebase functions.
How do I iterate over objects in a Firebase bucket?
2
Answers
buckets are very similar to filesystems. i believe in firebase you’re looking for something like /images/[userID]/[filename]
it should be pretty easy just to use your framework to do this. it’s unlikely you’ll need any ADDITIONAL firebase functions.
At first you should note that Google Cloud Storage does not have genuine "folders". In the Cloud Storage console, the files in your bucket are presented in a hierarchical tree of folders (just like the file system on your local hard disk) but this is just a way of presenting the files: there aren’t genuine folders/directories in a bucket.
The Cloud Storage console just uses the different parts of the file paths to "simulate" a folder structure, by using the "/" delimiter character.
This doc on Cloud Storage and gsutil explains and illustrates very well this "illusion of a hierarchical file tree".
So you can very well use the asynchronous
getFiles()
method to list the files in your bucket, but:forEach
loops mentioned in your question)As an example, the following HTTPS Cloud Function lists all the files (and "folders") in your default bucket: it log them in the Cloud Console Log and it returns an array of all these files.