【问题标题】:Send file from nodejs server to AngularJS client从 nodejs 服务器发送文件到 AngularJS 客户端
【发布时间】:2015-10-22 10:29:57
【问题描述】:

我想将文件从 node.js 服务器发送到 Angular 上的客户端。我在客户端使用 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 文件。 其他格式如何做到这一点?

【问题讨论】:

    标签: angularjs node.js filesaver.js


    【解决方案1】:

    检查这个: Failed to load PDF document - Angular JS - BLOB

    设置responseType

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

    【讨论】:

      猜你喜欢
      • 2016-04-04
      • 2022-01-12
      • 1970-01-01
      • 2015-05-02
      • 2020-08-17
      • 2015-03-05
      • 1970-01-01
      • 2018-07-23
      相关资源
      最近更新 更多