我允许用户上传大约20 MB的文件大小。我使用以下代码
创建javascript限制 if(window.File && window.FileReader && window.FileList && window.Blob){
var total_files_size = 0;
if(this.elements['file_attach[]'].files.length > maximum_files){
alert( "Can not select more than "+maximum_files+" file(s)");
proceed = false;
}
$(this.elements['file_attach[]'].files).each(function(i, ifile){
if(ifile.value !== ""){ //continue only if file(s) are selected
if(allowed_file_types.indexOf(ifile.type) === -1){ //check unsupported file
alert( ifile.name + " is unsupported file type!");
proceed = false;
}
total_files_size = total_files_size + ifile.size; //add file size to total size
}
});
if(total_files_size > allowed_file_size){
alert( "Make sure total file size is less than 20 MB!");
proceed = false;
}
然后我使用max_content_length来增加大小,如下所示:
app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 21 * 1024 * 1024
当我在没有gunicron的情况下运行我的应用程序时,它在本地运行正常。但是,当我在服务器中部署时,它不起作用。
我的gunicorn系统文件如下
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target network-online.target multi-user.target
[Service]
User=xxx
Group=www-data
WorkingDirectory=/home/ubuntu/flask_app
Environment="PATH=/home/ubuntu/flask_app/flask_app_env/bin"
ExecStart=/home/ubuntu/flask_app/flask_env/bin/gunicorn --workers 6 --bind unix:contact_form.sock -m 007 --max-requests 100 wsgi:app
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target network-online.target
任何帮助都是明确的
由于