前端
```js
download(fileName) {
this.axios
.post(
"/post/download",
{ content: fileName },
{ responseType: "blob" }
)
.then((response) => {
let blob = new Blob([response.data]);
let url = URL.createObjectURL(blob);
var eleLink = document.createElement("a");
eleLink.download = item.content;
eleLink.style.display = "none";
eleLink.href = url;
document.body.appendChild(eleLink);
eleLink.click();
document.body.removeChild(eleLink);
});
},
```
后端
```py
@app.route('/post/download', methods=['POST'])
def download():
item = flask.request.get_json(silent=True)
file_name = item['content']
print('downloading ...')
file_stream = client.download_stream(file_name) # 流式下载
print("downloaded")
return flask.send_file(file_stream, download_name=file_name, as_attachment=True)
```
0 Comments latest
No comments.