从 FileField 中的 django 模型将图像上传到 Firebase 存储
Upload image to Firebase Storage from django models in FileField
我需要将图像上传到 Firebase 存储,我想用 post_save 信号或保存方法来完成。但是由于 Firebase 是纯 JS,我怎么能在 models.py 中做到这一点?以下是如何使用 Firebase Web 上传的参考:
您将要为此使用 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')
我需要将图像上传到 Firebase 存储,我想用 post_save 信号或保存方法来完成。但是由于 Firebase 是纯 JS,我怎么能在 models.py 中做到这一点?以下是如何使用 Firebase Web 上传的参考:
您将要为此使用 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')