thisbejim / Pyrebase

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

get storage download url with service account? #257

Open lohriialo opened 6 years ago

lohriialo commented 6 years ago

I'm using service account, trying to get the download url of all the assets in my storage but I don't see a way, help please

firebase = pyrebase.initialize_app(firebase_config)
storage = firebase.storage()
files = storage.list_files()
for file in files:
    print(storage.child(file.name).get_url(None))

This gives me the storage url like so but the token is missing: https://firebasestorage.googleapis.com/v0/b/projectid.appspot.com/o/file.jpg?alt=media

How can I get the token for the file?

minhnhattonthat commented 5 years ago

When upload a file to storage while logged in as a user, it will return a response JSON that has a downloadToken property. You need to store this somewhere, then call get_url(token) with that downloadToken.

kartikbathla commented 3 years ago

seems like what we get on uploading is not a JSON file. I got this error upon trying to do as you advised 'NoneType' object is not subscriptable

DannyFGitHub commented 2 years ago

Does file.metadata contain 'firebaseStorageDownloadTokens'? Because the blobs returned by firebase_admin library contain a metadata attribute. The tokens appear to be there.

    blobs = storage_bucket.list_blobs()
    for blob in blobs:
        print(blob.metadata['firebaseStorageDownloadTokens'])