angularjs - akka-http 网络::err_incomplete_chunked_encoding 200 (ok)
问题描述
我正在尝试向浏览器发送一个大/通常很慢的响应,以使用 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 网络::err_incomplete_chunked_encoding 200 (ok)
在浏览器上。
我已经尝试过withRequestTimeOut
//并在客户端上设置了超时但没有任何效果withRequestTimeouResponse
?withoutSizeLimit
解决方案
如果代码使用它会更好responseType: 'blob'
:
$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'
},
̶r̶e̶s̶p̶o̶n̶s̶e̶T̶y̶p̶e̶:̶ ̶'̶a̶r̶r̶a̶y̶b̶u̶f̶f̶e̶r̶'̶
responseType: 'blob'
}).then
(function mySuccess(response) {
̶v̶a̶r̶ ̶b̶l̶o̶b̶ ̶=̶ ̶n̶e̶w̶ ̶B̶l̶o̶b̶(̶[̶r̶e̶s̶p̶o̶n̶s̶e̶.̶d̶a̶t̶a̶]̶,̶ ̶t̶y̶p̶e̶:̶ ̶'̶a̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶/̶v̶n̶d̶.̶o̶p̶e̶n̶x̶m̶l̶f̶o̶r̶m̶a̶t̶s̶-̶o̶f̶f̶i̶c̶e̶d̶o̶c̶u̶m̶e̶n̶t̶.̶s̶p̶r̶e̶a̶d̶s̶h̶e̶e̶t̶m̶l̶.̶s̶h̶e̶e̶t̶'̶)̶;̶
var blob = response.data;
savesAs(blob, "excel.xlsx")
})
推荐阅读
- php - MySQL + 调整当前查询以从另一个表中获取更多数据(每列)
- angular - 刷新谷歌地图中的动态图层
- git - 我可以分叉一个分叉的仓库来访问它,原始仓库是私有的吗?
- javascript - Javascript中调用方法中的thisarg混淆
- typescript - 通过静态字段初始化器避免类之间的依赖循环
- android - 自定义 EditText 到 Android
- ios - 如何使用 iPhone X 在我的应用程序中保存不同的 faceID 并稍后将它们与任何面部匹配 - iOS Swift
- php - 网站速度很慢,但如果我修改 URL,它会正常加载
- salesforce - 在字符串中使用自定义标签会引发“字段完整性异常”
- java-8 - 使用函数式编程对列表中的服务器对象进行流和过滤