【发布时间】:2020-10-10 06:12:01
【问题描述】:
@app.route('/', methods=['POST'])
def upload_file():
if request.method == 'POST':
if 'files[]' not in request.files:
flash('No file part')
return redirect(request.url)
files = request.files.getlist('files[]')
...Processing my multiple uploaded files in Flask App...
...
b64_encoded_list = base64.b64encode(json_encoded_list)
print(b64_encoded_list)
## b64_encoded_list is a simple string ##
buffer = BytesIO()
buffer.write(b64_encoded_list)
buffer.seek(0)
flash('File(s) successfully uploaded')
return send_file(buffer, mimetype="image/jpg", attachment_filename="license.pem", as_attachment=True)
现在我可以在 Web 应用程序部分发送和下载,但 .pem 文件已损坏,因为 b64_encoded_list 包含存储在 .pem 文件中的字符串的 b64 编码。但是从网络应用程序下载文件后,再次读取它给我一个错误 - encrypted = pickle.load(open(pemfile, "rb"))
错误 - UnpicklingError: 无效的加载键,'W'。
如何解决这个问题我也使用了 mimetype - application/x-x509-ca-cert,但还是同样的错误。
请帮忙!
提前致谢!!
【问题讨论】:
标签: html python-3.x flask pickle pem