【问题标题】:Upload image to Firebase Storage from django models in FileField将图像从 FileField 中的 django 模型上传到 Firebase 存储
【发布时间】:2016-07-27 20:37:31
【问题描述】:

我需要将图像上传到 Firebase 存储,我正在考虑使用 post_save 信号或使用 save 方法。但是由于 Firebase 是纯 JS,我如何在 models.py 中做到这一点?以下是如何使用 Firebase Web 上传的参考:

https://firebase.google.com/docs/storage/web/upload-files

【问题讨论】:

标签: django firebase firebase-storage


【解决方案1】:

您将要为此使用google-cloud-storage

# Import
from google.cloud import storage

# Initialize
client = storage.Client()
bucket = client.get_bucket('bucket-id-here')

# Download
blob = bucket.get_blob('remote/path/to/file.txt')
print blob.download_as_string()

# Upload
blob2 = bucket.blob('remote/path/storage.txt')
blob2.upload_from_filename(filename='/local/path.txt')

【讨论】:

    猜你喜欢
    • 2017-09-25
    • 2021-05-23
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    相关资源
    最近更新 更多