我想知道将 PDF 文件作为 HTML 表单的输入并将其发送到我的 Flask 应用程序以处理该文件的最简单方法是什么。有什么方法可以避免将文件本地保存在我的系统上?
HTML:
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data action = 'http://127.0.0.1:5000/uploadDoc'>
<input type=file name=file>
<input type=submit value=Upload>
</form>
烧瓶:
app = Flask(__name__)
UPLOAD_FOLDER = 'C:\\Users\\Tanoy Majumdar\\Documents\\Chekk_OCR\\'
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/uploadDoc', methods = ['POST', 'GET'])
def upload_file():
print("Hello")
if request.method == 'POST':
# check if 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 an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file:
filename = secure_filename(file.filename)
#file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
print(str(filename))
print (generate_kv(filename)) #generate_kv() converts pdf pages to images using pdf2image lib.
运行此应用程序时出现以下错误:
[2020-07-03 10:52:16,364] 应用程序错误:/uploadDoc [POST] 回溯异常(最近调用最后一次):文件“c:\users\tanoy majumdar\anaconda3\lib\site-packages\pdf2image \pdf2image.py”,第 436 行,在 pdfinfo_from_path 中引发 ValueError ValueError
慕森卡
相关分类