[英]How to download file from firebase storage in python using firebase_admin
我使用firebase_admin
成功地將文件上傳到 firebase 存儲,如下所示:
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")
但我的問題是我不知道如何使用 firebase_admin 模塊從 firebase 存儲下載文件。 請告訴我演示代碼如何使用 firebase_admin 從 firebase 存儲中下載該文件
你找到解決方案了嗎? 我正在嘗試下載圖像。 我能夠將字節寫入 txt 文件。 但是,我需要下載 url 或圖像。
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)
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)
只需將擴展名更改為 .jpg 即可,destination_file_name = r"localpath\file.jpg"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.