Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a folder in Firebase Storage?

So the new Firebase has support for storage using Google Cloud Platform.

You can upload a file to the images folder using:

var uploadTask = storageRef.child('images').put(file, metadata); 

What if you want to create a subfolder images/user1234 dynamically using code?

The offical sample does not show how to do that, nor the official guide or reference docs.

Is the Firebase Console the only place where folders can be created manually?

like image 242
Pier Avatar asked Jun 06 '16 18:06

Pier


People also ask

How do I upload folders to Firebase Storage?

There is no way to upload an entire folder to Cloud Storage for Firebase in one go. You will have to upload the individual files in the folder. The is no concept of an empty folder in Cloud Storage for Firebase. Folders only exist by the fact that they have files in them.

How do I get files from Firebase Storage?

To download a file, first create a Cloud Storage reference to the file you want to download. You can create a reference by appending child paths to the root of your Cloud Storage bucket, or you can create a reference from an existing gs:// or https:// URL referencing an object in Cloud Storage.

Can I delete a folder in Firebase Storage?

Actions: Identify the unique Firebase storage folder(virtual path) that needs to be deleted using the information from the document path on which the function is triggered. Access the storage account associated with the app in the function and delete the target folder.


2 Answers

The Firebase Storage API dynamically creates "folders" as intermediate products: if you create a file at images/user1234/file.txt, all intermediate "folders" like "images" and "user1234" will be created along the way. So your code becomes:

var uploadTask = storageRef.child('images/user1234/file.txt').put(file, metadata); 

Note that you need to include the file name (foo.txt for example) in the child() call, since the reference should include the full path as well as the file name, otherwise your file will be called images.

like image 103
Mike McDonald Avatar answered Oct 12 '22 11:10

Mike McDonald


The Firebase Console does allow you to create a folder, since it's the easiest way to add files to a specific folder there.

But there is no public API to create a folder. Instead folders are auto-created as you add files to them.

like image 28
Frank van Puffelen Avatar answered Oct 12 '22 12:10

Frank van Puffelen