Your error is resulting from the
BadRequestKeyError because of access to the key that doesn't exist in your
*** BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
Uploaded files are keyed under the
request.files and not the
request.form dictionary. Also, you need to use the loop as the value keyed under
u_img is the instance of
FileStorage and not at all iterable.
Please refer below updated code that will help you in resolving all of the issues.
@app.route('/', methods=['GET', 'POST'])
mytarget = os.path.join(app_root, 'static/img/')
if not os.path.isdir(mytarget):
if request.method == 'POST':
file = request.files['u_img']
file_name = file.myfilename or ''
mydestination = '/'.join([mytarget, file_name])