0

Currently I can upload images to the firebase storage with the Admin SDK using Python.

import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage


cred = credentials.Certificate("certificate.json")
firebase_admin.initialize_app(cred, { 'storageBucket' : 'AppName-addc4.appspot.com'})


bucket = storage.bucket()
blob = bucket.blob('/imageName')
imagePath = "/Users/name/Desktop/IMG_1895.jpg"
blob.upload_from_filename(imagePath)

If I upload an image it creates a standard folder and inside there is my image. enter image description here

How I can rename this folder like myImages instead of the /

adri567
  • 533
  • 5
  • 20

2 Answers2

2

Cloud Storage doesn't really have "folders" that work like a computer filesystem. Each object has a unique path, and the path has components that look like folders that are delimited by slashes, and help you organize your content, but no folders actually exist, and you can't rename them. The way to effectively change the name of one of these "folders" is to copy all of the files under it into a new path with the name you want, and the "folder" you see will disappear from view when it no long appears to contain any objects.

See also:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Is there a way to create a new "folder" instead of rename it using python? So I mean I can do this manually in firebase storage. Is there a way to do this programmatically? – adri567 Aug 07 '20 at 15:18
  • 1
    You don't need to do anything to create a folder. Just start writing objects to it, and it will appear in the console automatically. It does not work like "mkdir" in a normal filesystem. – Doug Stevenson Aug 07 '20 at 15:40
  • sorry I misread your answer, my english is not very gut. Now I understand :) – adri567 Aug 07 '20 at 15:48
1

There is a "create folder" option besides "Upload File" button for a bucket in Storage console.

One can create folders in bucket and upload files to it on console.

To create such folders in bucket using admin APIs, add folders before file reference. e.g.

const blob = bucket.file('folder1/folder2/' + req.file.originalname);  
Ruvee
  • 8,611
  • 4
  • 18
  • 44
Chirag Dave
  • 786
  • 6
  • 5