If user doesn't select a file in form (equals PHP UPLOAD_ERR_NO_FILE
), request.files['file']
also return a FileStorage
object, I am using request.files['file'].filename == ''
to check, any better way ? I have seen Flask Doc but can't find the answer.
'file' in request.files
will not work on user doesn't select file, browser also will submit a 0 length and filename equals '' (empty string) part.
and how do I detect uploaded file was only partially uploaded error (equals PHP UPLOAD_ERR_PARTIAL) ?
Now I am using
if request.files['file'].filename == '':
return 'No selected file'
or using file length check
import os
file = request.files['file']
file.seek(0, os.SEEK_END)
if file.tell() == 0:
return 'No selected file'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With