gpt4 book ai didi

angularjs - 将文件从nodejs服务器发送到AngularJS客户端

转载 作者:太空宇宙 更新时间:2023-11-04 02:23:32 24 4
gpt4 key购买 nike

我想在 Angular 上将文件从 node.js 服务器发送到客户端。我在客户端上使用 fileSaver.js。

服务器:

res.download('123.txt', function(err){
if(err){
console.log('error');
}
})

客户:

$http.post('/downloadFile').success(function(res){
var file = new Blob([res]);
saveAs(file, '123.txt');
}

但它仅适用于 .txt 文件。如何使用其他格式执行此操作?

最佳答案

检查一下: Failed to load PDF document - Angular JS - BLOB

设置响应类型:

$http.post('/downloadFile','', {responseType:'arraybuffer'}).success(function(res){.....}

关于angularjs - 将文件从nodejs服务器发送到AngularJS客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31734390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com