I'm trying to upload user selected image into my firebase.
When I browse for the file
file = request.files['inputFile']
and I try this
storage.child("images/examples.jpg").put(file)
I get an error
io.UnsupportedOperation: fileno
How do I go about fixing this? I just want user to select the file and I be able to make use of the .jpg file and upload it
The put
method takes a path to a local file (and an optional user token).
request.files[key]
returns a custom object that represents the uploaded file. Flask documentation links: file uploads quickstart , incoming request data api , FileStorage class .
You need to store the uploaded file data to a local file, and the pass that file name to the put
method:
request.files['inputFile'].save("some_filename.ext")
storage.child("images/examples.jpg").put("some_filename.ext")
Look into the tempfile
module to generate random temporary file names (instead of using the hard coded some_filename.ext
, which obviously is not a very good idea with concurrent requests).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.