2016-07-27 130 views
0

我需要将图片上传到Firebase存储,我正在考虑使用post_save信号或保存方法。但是由于Firebase是纯JS,我怎样才能在models.py中做到这一点?下面是如何与火力地堡网络上传参考:从FileField的django模型将图片上传到Firebase存储

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

+0

见小李的答案在这里最后一个注释是:http:/ /stackoverflow.com/questions/38521949/is-there-any-supported-way-for-a-firebase-service-accounts-to-write-to-your-clou/38532457#38532457 –

回答

1

你会想用gcloud-python此:

# Import 
from gcloud 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') 
相关问题