[英]How do you upload a file to Firebase Storage using Python Flask?
我想上傳一個文件,但是我在stackoverflow上看到的示例是基於使用blobl.upload_from_string
,它與我使用圖像的用例不匹配。
您可以從Flask的request.files
獲取文件對象,並將其與blob.upload_from_file
一起發送以上傳二進制文件。
from werkzeug.utils import secure_filename
def uploadPhoto(userIDStr, file):
path = '/bucketname/'+str(secure_filename(file.filename))
if file:
try:
bucket = storage.bucket()
#file is just an object from request.files e.g. file = request.files['myFile']
blob = bucket.blob(file.filename)
blob.upload_from_file(file)
except Exception as e:
console.log('error uploading user photo: ' % e)
相關文檔位於Blob的頁面下: http : //google-cloud-python.readthedocs.io/en/latest/storage/blobs.html#google.cloud.storage.blob.Blob.upload_from_file
當使用沒有最詳盡的用例示例的python庫時,可以使用IPython
探索對象,然后在objectname.
后按TAB
objectname.
查看其方法和成員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.