【问题标题】:Angular weird behaviour when downloading from a stream从流下载时出现角度奇怪的行为
【发布时间】:2018-11-19 22:55:50
【问题描述】:

我的 Java 后端有一个休息控制器,用于将文件下载为流:端点返回一个 StreamingResponseBody 流,当我尝试使用 curl 下载文件时,它工作正常:

curl -H "Authorization: Bearer <MyToken>" http://localhost:9001/rest/api/download --output test.zip

但不是 angular,我使用的是 HttpModule get 方法:

this.http.get(url, headers).subscribe ...

但是我可以在chrome开发者工具的网络面板中看到文件正在下载,但我不知道文件保存在哪里,就好像它是流式传输而不是下载一样:

任何人都可以解释这种行为,以及如何下载流而不是广播它。

【问题讨论】:

    标签: java angular networking download stream


    【解决方案1】:

    也许你可以试试……

    this.http.get(`your_url`, { headers: headers, responseType: 'blob', observe: 'response'})
              .map( res => (
                   {
                    content: res.body, 
                    fileName: res.headers.get('content-filename')
                   }
               ));
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 2021-07-12
      相关资源
      最近更新 更多