Note that there are some explanatory texts on larger screens.

plurals
  1. POForward a file upload stream to S3 through Iteratee with Play2 / Scala
    primarykey
    data
    text
    <p>I've read some stuff about the possibility to send a file to S3 through Iteratee, which seems to permit to send so S3 chunks of a file as we receive them and avoid an OutOfMemory for large files for exemple.</p> <p>I've found this SO post which is probably almost what i need to do: <a href="https://stackoverflow.com/questions/11916911/play-2-x-reactive-file-upload-with-iteratees">Play 2.x : Reactive file upload with Iteratees</a> I don't really understand how to do it, or either if it's really available in Play 2.0.2 (because Sadek Brodi says foldM is available in Play 2.1 only for exemple)</p> <p>Can someone explain this in a simple way, for someone who have read some blog about Iteratees, and is not yet a Scala/Play2 expert?</p> <p>I don't even know if i should use a multipart body parser or something like that, but one thing i know is that i don't understand what this code is doing:</p> <pre><code>val consumeAMB = Traversable.takeUpTo[Array[Byte]](1028*1028) &amp;&gt;&gt; Iteratee.consume() val rechunkAdapter:Enumeratee[Array[Byte],Array[Byte]] = Enumeratee.grouped(consumeAMB) val writeToStore: Iteratee[Array[Byte],_] = Iteratee.foldM[Array[Byte],_](connectionHandle){ (c,bytes) =&gt; // write bytes and return next handle, probable in a Future } BodyParser( rh =&gt; (rechunkAdapter &amp;&gt;&gt; writeToStore).map(Right(_))) </code></pre> <hr> <p>By the way, what will be the difference in memory consumption compared to using classic Java InputStream / OutputStream. I actually am able to forward a 500mb file to S3 in a non-blocking way, with a very low memory consumption, without using Iteratees, using Java + AsyncHttpClient + Grizzly (but I guess it would also work with Netty).</p> <p>So what's the advantage of using Iteratee?</p> <p>One difference I can see is that the InputStream I get and forward to S3 is in my case backed by a temporary file (this is a CXF behavior), so it may not be as reactive as Play Iteratee</p> <p>But with Iteratees, if the Enumerator produces bytes received by the connection and forward them to S3 through an Iteratee, then if the connection to S3 is not good and the bytes can't be forwarded very fastly, where are stored the "pending" bytes?</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.
 

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