Earlier, I wrote on Stack Overflow and unfortunately did not get an answer there.

I have problem witch FileStorage object in Flask. I want convert upload file to BLOB. To get a BLOB from image I need the contents of the file for example in binary code. I have read that it is enough to call the read() method.

Example:

request.files['image'].read() #output b'binary'

Actually the output binary code is empty.I tested do FileStorage doesn't download file. Flask donwload filename and mimetype, but not file content.

Test:

if request.files['avatar']:
   print(request.files['image'])          #output <FileStorage: 'image.jpg' ('image/jpeg')>
   print(request.files['image'].mimetype) #output image/jpeg
   print(request.files['image'].read())   #output b''
I tested do the same situation is exist if I saving file in local directory. If I saving file in directory, then I have file the same filename and mimetype, but is empty. The image size is 0 bytes.

Conclusion:

My Flask FileStorage have a filename and mimetype but doesn't have the content of the file.

I got a notification that my question was marked as a duplicate question ,,[Sending data from HTML form to a Python script in Flask](https://stackoverflow.com/questions/11556958/sending-data-from-html-form-to-a-python-script-in-flask. Refer to the responses in this thread. My code meets the conditions specified in the reply to the thread:

  • action: The URL that the form data is sent to on submit. Generate it with url_for. It can be omitted if the same URL handles showing the form and processing the data.

  • method="post": Submits the data as form data with the POST method. If not given, or explicitly set to get, the data is submitted in the query string (request.args) with the GET method instead.I use POST.

  • enctype="multipart/form-data": When the form contains file inputs, it must have this encoding set, otherwise the files will not be uploaded and Flask won't see them.
    The input tag needs a name parameter.
    The situation has not changed. My Flask FileStorage have a filename and mimetype but doesn't have the content of the file.