0

I successfully uploaded file to firebase storage using firebase_admin like this:

from firebase_admin import db
from firebase_admin import credentials
from firebase_admin import storage
from uuid import uuid4

cred = credentials.Certificate('key.json')
firebase_admin.initialize_app(cred, {
    'databaseURL' : 'https:url.firebaseio.com/', 'storageBucket': 'bucket.appspot.com'
})
bucket = storage.bucket()
blob = bucket.blob("myfile.txt")
new_token = uuid4()
metadata  = {"firebaseStorageDownloadTokens": new_token}
blob.metadata = metadata
blob.download_from_filename(filename="myfile.txt")

But my issue is I don't know how to download file from firebase storage using firebase_admin module. Please tell me a demo code how can I download that file from firebase storage using firebase_admin

2 Answers2

1

Did you find the solution?. I'm trying to download an image. I'm able to write the bytes to a txt file. However, i need to download url or the image.

from firebase_admin import credentials, initialize_app, storage

cred = credentials.Certificate(r"credential_location.JSON")
initialize_app(cred, {'storageBucket': 'xxxxxxxx.appspot.com'})

source_blob_name = "pic5.jpg"
bucket_name = "xxxxxxxxx.appspot.com"

#The path to which the file should be downloaded
destination_file_name = r"localpath\file.txt"


bucket = storage.bucket()
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
Ghani
  • 51
  • 1
  • 7
  • Change the file name extension to jpg and you will download the image, I tested. To download the url I recommend this: https://www.sentinelstand.com/article/guide-to-firebase-storage-download-urls-tokens – Randolfo Jan 10 '22 at 23:38
0
   from firebase_admin import credentials, initialize_app, storage

cred = credentials.Certificate(r"credential_location.JSON")
initialize_app(cred, {'storageBucket': 'xxxxxxxx.appspot.com'})

source_blob_name = "pic5.jpg"
bucket_name = "xxxxxxxxx.appspot.com"

#The path to which the file should be downloaded
destination_file_name = r"localpath\file.txt"


bucket = storage.bucket()
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)

just change the extension to .jpg and it will work, destination_file_name = r"localpath\file.jpg"