![](/img/trans.png)
[英]How to download file from firebase storage in python using firebase_admin
[英]Read JSON file from Firebase Storage using Admin SDK in Python without download
我正在通過 Python 成長,通過管理員 sdk 讀取 Firebase 存儲中存在的 JSON 文件。我已經閱讀了以下問題
如何使用 firebase_admin 從 python 中的 firebase 存儲下載文件
但在這種情況下,文件被下載到另一個文件。 是否可以在不下載和不公開的情況下閱讀它? 或者是否可以制作一個臨時文件,一旦 python 打印出來就刪除它? 謝謝
我的代碼:
import firebase_admin
from firebase_admin import credentials, storage
cred = credentials.Certificate('serviceAccount.json')
firebase_admin.initialize_app(cred, {
"storageBucket": "**.appspot.com"
})
source_blob_name = "UQ4ADY.json"
#The path to which the file should be downloaded
destination_file_name = r"temp\ftmp.json"
bucket = storage.bucket()
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
請注意,可能會有很多請求,這就是為什么我不想下載文件
在 Johm Hanley 發表評論后,我使用了download_as_text
函數:
import firebase_admin
from firebase_admin import credentials, storage
cred = credentials.Certificate('serviceAccount.json')
firebase_admin.initialize_app(cred, {
"storageBucket": "**.appspot.com"
})
source_blob_name = "UQ4ADY.json"
#The path to which the file should be downloaded
destination_file_name = r"temp\ftmp.json"
bucket = storage.bucket()
blob = bucket.blob(source_blob_name)
data = blob.download_as_text()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.