akka-http net :: err_incomplete_chunked_encoding 200(确定)

问题描述 投票:0回答:1

我正在尝试使用Akka-http向浏览器发送较大/通常较慢的响应,以使其呈现为excel文件:即:]]

使用ui代码
$http({
  method : "post",
  url: "myUrl",
  data: "large amount of request data to run a api call",
  headers: {
    'Content-type': 'application/json',
    'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  },
  responseType: 'arraybuffer'
}).then
  (function mySuccess(response) {
    var blob = new Blob([response.data], type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    savesAs(blob, "excel.xlsx")
}) 

缓慢的api运行,我尝试将数据分块,即:

path(myPath) {
  post {
    entity(as[MyPredicates]) { entity =>
      val slowApi = Future[List[Results]] = runSlowApi(entity)
      val excel = slowApi.map(data => generateExcel(data)).toByteArray
      val source = Source.fromFuture(excel).map(ByteString.apply)
      val chunkStream = source.via(new Chunker(chunkSize = 8192))
      chunkStream.keepAlive(1.second, () => TextMessage.Strict("ping"))
      complete(HttpEntity(MediaTypes.`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`, chunkStream)
  }
}

对于少于60秒的任何东西,它都可以正常工作,但是60秒之后,它总是会失败,并带有

akka-http net :: err_incomplete_chunked_encoding 200(确定)

在浏览器上。

我尝试过withRequestTimeOut /withRequestTimeouResponse/ withoutSizeLimit并在客户端上设置超时,但没有任何效果吗?

我正在尝试使用Akka-http:将大/经常缓慢的响应发送到浏览器,以呈现为excel文件,即:在ui代码$ http({方法中:“ post”,url:“ myUrl”,数据:“大量...

angularjs scala akka akka-stream akka-http
1个回答
0
投票

如果代码使用responseType: 'blob',效果会更好:

© www.soinside.com 2019 - 2024. All rights reserved.