pythonfirebasefirebase-storagepyrebase

Trying to upload a file to firebase storage using pyrebase


I have been working on an app and have discovered accessing firebase storage using pyrebase.

import pyrebase

config = {
  "apiKey": "API",
  "authDomain": "DOMAIN",
  "databaseURL": "URL",
  "projectId": "ID",
  "storageBucket": "STORE_BUCKET",
  "messagingSenderId": "SEND_ID",
  "appId": "APP_ID",
  "serviceAccount": "PATH_TO_KEY"
}

firebase_storage = pyrebase.initialize_app(config)
storage = firebase_storage.storage()
storage = firebase_storage.storage()
storage.child("IMAGE.jpeg").put("IMAGE.jpeg")

I have been able to successfully upload files but is there any way I can upload it to a specific folder in my firebase storage??


Solution

  • As shown in the documentation of Pyrebase on writing files, you can specify a path on the server where to write the file by specifying that path with slashes in the child() call. From the docs:

    storage = firebase.storage()
    # as admin
    storage.child("images/example.jpg").put("example2.jpg")
    

    This takes the local example2.jpg file and writes it into the images folder on Cloud Storage with name example.jpg.