如何使用 Python 从 Firebase 存储中检索图像?

Kai*_*Kai 4 python firebase firebase-storage

我已经将我的图像存储到 Firebase Storage,我需要使用 Python 代码将其取出。我可以使用任何 URL 检索图像吗?或者有什么办法可以取出来?

这是我如何将它存储在 Firebase 存储中的图像:

这是我如何将它存储在 Firebase 存储中的图像

Che*_*che 7

这就是我使用的。希望能帮助到你。

import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage

# Fetch the service account key JSON file contents
cred = credentials.Certificate("credentials.json")

# Initialize the app with a service account, granting admin privileges
app = firebase_admin.initialize_app(cred, {
    'storageBucket': '<BUCKET_NAME>.appspot.com',
}, name='storage')

bucket = storage.bucket(app=app)
blob = bucket.blob("<your_blob_path>")

print(blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET'))
Run Code Online (Sandbox Code Playgroud)

它会生成一个公共 URL(300 秒)供您下载文件。

例如,在我的情况下,我使用该 URL 显示我的 django 网站中存储的带有<img>标签的图片。

是更多有用功能的文档。