I am using Flask to render some analysis based on taking image as an input using Flask reuploaded and werkzeug. Though the input accepts multiple images, the output is rendered of only one image instead of all the images that were uploaded. There is no error message that I am receiving.
HTML code:
<form method="POST" action="" enctype="multipart/form-data"><p>
<input type="file" name="file" multiple
accept="image/x-png,image/gif,image/jpeg">
<input type="submit" value="Upload">
Post request
@app.route('/', methods=['POST'])
def upload_image():
if request.method == 'POST':
# checks whether or not the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No file selected for uploading')
return redirect(request.url)
files = request.files.getlist('files[]')
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(os.getcwd() +
UPLOAD_INPUT_IMAGES_FOLDER, file.filename))
flash('File successfully uploaded')
# calls the ocr_processing function to perform text extraction
extracted_text = ocr_processing(file)
print(extracted_text)
match = extracted_text.lower()
df = pd.read_csv("/Users/ri/Desktop/DPL/DPL.csv")
for row in df.Pattern_String:
result = ratio(row, match)
print(result)
if result >= 10:
else:
return render_template('uploads/results.html',
msg='Processed successfully!',
match=match,
img_src=UPLOAD_INPUT_IMAGES_FOLDER + file.filename)
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)
You define files = request.files.getlist('files[]')
, but then you do not use it.
You need to iterate over all uploaded files, ie you need e.g. a for loop.
I would start renaming the misleading input name file
to files
and then start over.