thisbejim / Pyrebase

A simple python wrapper for the Firebase API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

list_files() is returning with an error.

fortysev-en opened this issue · comments

I'm trying to get a list of all the available files under my bucket with list_files() function, however, getting an error every time.

AttributeError: 'Storage' object has no attribute 'bucket'

Please help me with a workaround.

I think you will need to use a service account to use the list files function.

In the firebase console, click the scroll nut icon besides the Project Overview, then Project Settings -> Service Accounts -> generate new private keys. This will give you a json file.

Add the json file to the config of pyrebase, you are looking for something like this:

config = {
  "apiKey": "apiKey",
  "authDomain": "projectId.firebaseapp.com",
  "databaseURL": "https://databaseName.firebaseio.com",
  "storageBucket": "projectId.appspot.com",
  "serviceAccount": "path/to/serviceAccountCredentials.json"
}

and then you should be able to use the list_files function by

storage = firebase.storage()
blobs = storage.list_files()
for blob in blobs:
  print(blob.name)

Hope this can help you.

Thank you for your quick response! This solution works exactly as I wanted. Unfortunately, I won't be able to use this feature as I can't send this private key on client side.