I'm following the file uploads example from the Flask docs.
There is an if file
check before saving the file. When does this return false? It's already been checked that the file does exist and has a filename. It returns True when the file is empty.
If the file is None, the file not in request.files
returns False, so the code never gets to the if file
part. I just want to know why this check is done.
I have a feeling this question is probably silly and obvious, but I wasn't able to find anything on Google.
Snippet:
@app.route('/file/<string:filename>', methods=['POST'])
def upload_file(filename):
if 'file' not in request.files:
return "No file part in request", 400
file = request.files['file']
if file.filename == '':
return "No selected file", 400
if file:
filename = secure_filename(filename)
file.save(os.path.join(UPLOAD_FOLDER, filename))
return "File uploaded successfully"
else:
return "Something went wrong but I don't know what", 400