我正在用flask dropzone将一个文件上传到flask服务器。 然后用客户端下载的另一个文件响应dropzone。问题是,这段代码只在程序不花太多时间处理上传的文件,只发送一些有点静态的东西时才起作用
简言之,服务器响应的时间越长,客户端响应响应的可能性就越小;无法下载随响应一起发送的文件
<p> Drop your csv file including the addresses here </p>
{{ dropzone.create('/upload') }}
<button id="upload">Upload</button>
{{ dropzone.load_js() }}
{{ dropzone.config(custom_init="this.on('success', function(info,response)
{
var csvfile = JSON.parse(response)['file'];
console.log(csvfile);
console.log('Successfully downloaded file!')
const blob = new Blob([csvfile], {type:'text/csv'});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('hidden','');
a.setAttribute('href', url);
a.setAttribute('download', 'predictions.csv');
document.body.appendChild(a)
a.click();
document.body.removeChild(a);})") }}
@app.route('/upload', methods=['GET', 'POST'])
@login_required
def upload():
if current_user.is_subscribed:
model = load_model()
if request.method == 'POST':
for key, file in request.files.items():
if key.startswith('file'):
csvfile = update_csv(model=model, file=list(reader(codecs.iterdecode(file, 'utf-8-sig'), delimiter=";")))
#---------- Get updated csv file with predictions
response = json.dumps({'file': csvfile})
print("Sending response:")
return response
return render_template('upload.html', response=response)
return redirect(url_for("index"))
有什么解决办法吗
目前没有回答
相关问题 更多 >
编程相关推荐