我已经将图像存储到 Firebase Storage,我需要使用 Python 代码将其取出。我可以使用任何 URL 检索图像吗?或者有什么办法可以找回来吗?
以下是我如何将其存储在 Firebase Storage 中的图像:
这就是我用的。希望能帮助到你。
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'))
它生成一个公共网址(300 秒)供您下载文件。
例如,在我的例子中,我使用该 URL 来显示我的 django 网站中存储的图片<img>
tag.
Here https://googleapis.github.io/google-cloud-python/latest/storage/blobs.html#google.cloud.storage.blob.Blob是更多有用功能的文档。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)