【问题标题】:How to download file from firebase storage in python using firebase_admin如何使用firebase_admin从python中的firebase存储下载文件
【发布时间】:2022-01-03 12:18:26
【问题描述】:

我使用 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 存储下载该文件

【问题讨论】:

    标签: python firebase download firebase-storage firebase-admin


    【解决方案1】:

    您找到解决方案了吗? 我正在尝试下载图像。我能够将字节写入 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)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-28
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 2019-11-25
    相关资源
    最近更新 更多