我想知道將 PDF 文件作為 HTML 表單的輸入并將其發(fā)送到我的 Flask 應用程序以處理該文件的最簡單方法是什么。有什么方法可以避免將文件本地保存在我的系統(tǒng)上?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.運行此應用程序時出現(xiàn)以下錯誤:[2020-07-03 10:52:16,364] 應用程序錯誤:/uploadDoc [POST] 回溯異常(最近調(diào)用最后一次):文件“c:\users\tanoy majumdar\anaconda3\lib\site-packages\pdf2image \pdf2image.py”,第 436 行,在 pdfinfo_from_path 中引發(fā) ValueError ValueError
如何在 HTML 上上傳 pdf 文件并在 FLASK 后端處理它?
慕田峪7331174
2023-02-15 15:21:08