for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=True): interpreter.process_page(page)
text = retstr.getvalue()
fp.close() device.close() retstr.close() return text
报错
1
line 27, in getfile fp = open(request_data, 'rb').decode("utf-8") TypeError: expected str, bytes or os.PathLike object, not FileStorage
解决方案
The request.files['file'] is an instance of a FileStorage class (see also http://flask.pocoo.org/docs/0.12/api/#flask.Request.files), so you can’t do the fp = open(request_data, 'rb'). The FileStorage object contains a stream attribute that should point to an open temporary file, and probably you can pass that to PDFPage.get_pages()
for page in PDFPage.get_pages(file.stream, pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=True): interpreter.process_page(page)