Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay Framework [2.2-scala]: creating Enumerator from a slow InputStream
    primarykey
    data
    text
    <p>I'm implementing a AWS S3 file delivery API. I'm forced to stream the bytes from S3's S3ObjectInputStream to the browser. We have a use case were serving the file with cloudfront is not an option (mainly local development)</p> <p>I have an InputStream, so the most obvious thing to do would be to use Ok.chunked with an Enumerator.fromStream(), but the Enumerator.fromStream() has a very clear warning that the stream should not be slow. I'm assuming that an AWS S3ObjectInputStream is probably one of the slowest stream there is.</p> <p><a href="http://www.playframework.com/documentation/2.2.x/api/scala/index.html#play.api.libs.iteratee.Enumerator%24" rel="nofollow">http://www.playframework.com/documentation/2.2.x/api/scala/index.html#play.api.libs.iteratee.Enumerator$</a></p> <pre><code>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. </code></pre> <p>So I was wondering what the safest way is to avoid thread starvation and get the file streaming to the browser without holding the entire file in memory.</p> <p>Is there another way to get an Enumerator (or something we can send in a Result) from an InputStream?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload