用Akka作为httpresponse的流文件的流内容
我正在通过Java FileInputStream读取大文件的一部分,并希望将其内容汇回客户端(以Akka httpresponse的形式)。我想知道这是否可能,以及我将如何做到这一点?
从我的研究中,可以使用EntityStreamingSupport,但仅支持JSON或CSV数据。我将从文件中流式传输原始数据,该数据不会以JSON或CSV的形式流传输。
I am reading parts of large file via a Java FileInputStream and would like to stream it's content back to the client (in the form of an akka HttpResponse). I am wondering if this is possible, and how I would do this?
From my research, EntityStreamingSupport can be used but only supports json or csv data. I will be streaming raw data from the file, which will not be in the form of json or csv.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用akka-http和scala,则可以使用
getfromfile
将整个二进制文件从path
将整个二进制文件流式传输到httpresponse
之类的。此文件上传/下载往返Akka-http示例:
https://github.com/ pbernet/akka_streams_tutorial/blob/f246BC061A8F5A1ED9F79CCE3F4CCE3F4C52C3C9E1B57A/SRC/MAIN/SCALA/SCALA/AKKKAHTTP/htttpfileecho.scala#l52
堆尺寸。
但是,如果需要,可以这样做手动块:
Assuming you use akka-http and Scala you may use
getFromFile
to stream the entire binary file from apath
to theHttpResponse
like this:Taken from this file upload/download roundtrip akka-http example:
https://github.com/pbernet/akka_streams_tutorial/blob/f246bc061a8f5a1ed9f79cce3f4c52c3c9e1b57a/src/main/scala/akkahttp/HttpFileEcho.scala#L52
Streaming the entire file eliminates the need for "manual chunking", thus the example above will run with limited heap size.
However, if needed manual chunking could be done like this: