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

2024-04-20 11:09:22 发布

您现在位置:Python中文网/ 问答频道 /正文

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

以下是我如何将其存储在Firebase存储中的图像:

Here are the image of how I store it in Firebase Storage


Tags: 代码图像urlfirebase办法
1条回答
网友
1楼 · 发布于 2024-04-20 11:09:22

这就是我用的。希望有帮助。在

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'))

它生成一个公共URL(持续300秒),供您下载文件。在

例如,在我的例子中,我使用这个URL来显示我的django网站中存储的带有<img>标记的图片。在

Here是更多有用函数的文档。在

相关问题 更多 >