thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.07k stars 528 forks source link

list_files() is returning with an error. #408

Closed fortysev-en closed 2 years ago

fortysev-en commented 2 years ago

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.

Mick609 commented 2 years ago

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.

fortysev-en commented 2 years ago

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.