python - Upload image received via Flask to Firebase Storage -


i trying upload image firebase storage. image passed via http post. request processed using flask. can't seem image upload correctly. when specify image's location can upload image, ruling out issue firebase or code. have tried file location, unfortunately flask has prevented safety(probably thing). there need process image before storing it?.

i using postman send post request.

@message_api.route('/messenger/message/send/picture/individual', methods=['post']) def send_individual_picture():     picture = request.files['picture']      firebase.storage().put(picture) 

since firebase.storage().put() expects file path, you'll need save upload file first before can store it.

right have this:

@message_api.route('/messenger/message/send/picture/individual', methods=['post']) def send_individual_picture():     picture = request.files['picture']      firebase.storage().put(picture) 

after this, picture instance of werkzeug's filestorage class, can treated file descriptor. can stuff read() it.

since code treating file transient , don't need hanging around afterward, can use namedtemporaryfile creates temporary file name. can delete temporary file afterward.

import os import tempfile  @message_api.route('/messenger/message/send/picture/individual', methods=['post']) def send_individual_picture():     picture = request.files['picture']      temp = tempfile.namedtemporaryfile(delete=false)     picture.save(temp.name)     firebase.storage().put(temp.name)      # clean-up temp image     os.remove(temp.name) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -