我正在实现AWS S3文件传输API。我被迫把S3的S3ObjectInputStream中的字节流到浏览器。 我们有一个使用cloudfront服务的文件不是一个选项(主要是本地开发)Play Framework [2.2-scala]:从缓慢的InputStream创建枚举器
我有一个InputStream,所以最明显的事情就是使用Ok.chunked与Enumerator.fromStream( ),但Enumerator.fromStream()有一个非常明确的警告,即流不应该很慢。我假设AWS S3ObjectInputStream可能是最慢的流之一。
def fromStream(input: InputStream, chunkSize: Int = 1024 * 8)
(implicit ec: ExecutionContext): Enumerator[Array[Byte]]
Create an enumerator from the given input stream.
This enumerator will block on reading the input stream, in the default iteratee
thread pool. Care must therefore be taken to ensure that this isn't a
slow stream. If using this with slow input streams, consider setting the value
of iteratee-threadpool-size to a value appropriate for handling the blocking.
所以我想最保险的办法就是避免线程饥饿并获得文件流媒体浏览器未持有整个文件在内存中。
是否有另一种方法从InputStream获得一个枚举器(或者我们可以在一个Result中发送的东西)?
另一种使用情况是自定义授权在S3中的对象,那么你需要流式传输字节... – Jaap
也许你可以使用unfoldM? –
您是否找到任何解决方案? – nachokk