0

我正在使用 Flask 来呈现一些分析,这些分析基于使用 Flask reuploaded 和 werkzeug 将图像作为输入。尽管输入接受多张图像,但输出仅呈现一张图像,而不是上传的所有图像。我没有收到任何错误消息。

HTML 代码:

<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">

发布请求

@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)
4

1 回答 1

0

您定义files = request.files.getlist('files[]'),但随后您不使用它。

您需要遍历所有上传的文件,例如,您需要一个 for 循环。

我会开始将误导性输入名称重命名filefiles,然后重新开始。

于 2021-07-19T17:24:47.823 回答