簡體   English   中英

如何使用Python Flask將文件上傳到Firebase存儲?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM