【发布时间】:2020-06-05 08:19:14
【问题描述】:
我有以下烧瓶应用程序
fileform.html:
<html>
<head>
<title>Simple file upload using Python Flask</title>
</head>
<body>
<form action="/getSignature" method="post" enctype="multipart/form-data">
Choose the file: <input type="file" name="photo"/><BR>
<input type="submit" value="Upload"/>
</form>
</body>
</html>
app.py:
import os
from flask import Flask, request, render_template, url_for, redirect
app = Flask(__name__)
@app.route("/")
def fileFrontPage():
return render_template('fileform.html')
@app.route("/getSignature", methods=['POST'])
def handleFileUpload():
if 'photo' in request.files:
photo = request.files['photo']
if photo.filename != '':
filepath = os.path.join('/flask/files', photo.filename)
photo.save(filepath)
return render_template('result.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
这适用于较小的文件,但不适用于较大的文件。
单击上传按钮后,浏览器显示(Uploading 13%..),然后浏览器超时并显示ERR_CONNECTION_RESET。在烧瓶应用程序中看不到任何错误。
我通过 Nginx 提供服务。当我检查 nginx 日志时,我看到了
2020/02/20 22:38:47 [error] 6#6: *170614 client intended to send too large body: 80762097 bytes, client: 10.2.16.178, server: localhost, request: "POST /getSignature
我需要为此添加任何 Nginx 配置吗?
我想上传最大为 100Mb 的文件。
【问题讨论】:
-
你是如何运行 app.py 的?在控制台/ide 中还是通过 apache/nginx 之类的 Web 服务器运行?
-
请不要说你使用的是开发服务器