You could probably use `grouped(2).map { case Seq(a, b) => (a, b) }` and then use a graph with an `Unzip` stage ...
Heiko -- Heiko Seeberger Home: heikoseeberger.de <http://heikoseeberger.de/> Twitter: @hseeberger <https://twitter.com/hseeberger> Public key: keybase.io/hseeberger <https://keybase.io/hseeberger> > On 11 Sep 2015, at 16:10, lucian enache <cors...@gmail.com> wrote: > > Hello everyone, for akka-http when handling a POST request, if I have my > entity as a Multipart.FormData , > and I POST some JSON and a binary file, how can I split the two when I parse > the formData ? > > This is what I come up with so far > > path("upload") { /* uploads a file to the database */ > post { > entity(as[Multipart.FormData]) { (formData) => > > > val uploadedUrlsFuture = > formData.parts.map(_.entity.dataBytes).mapAsync(parallelism = 1)(part => > part > .map(_.toArray) > .runFold(ByteString())((totalBytes, bytes) => totalBytes ++ > bytes) > .map(_.toArray[Byte]).map(ResourceManager.saveFile(_)) /* > TODO update this to a service */ > ).grouped(100).runWith(Sink.head) > complete(OK) > } > } > } > > > So if I have an Content-Length of 2 in a scenario where I post an JSON Object > and a binary file, > is there a way to split that up and handle the two separately? > > And is this a good way to provide an upload functionality to a backend trough > akka-http and akka-streams (are there better ways to achieve this)? > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/> > >>>>>>>>>> Check the FAQ: > >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html> > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > >>>>>>>>>> <https://groups.google.com/group/akka-user> > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to akka-user+unsubscr...@googlegroups.com > <mailto:akka-user+unsubscr...@googlegroups.com>. > To post to this group, send email to akka-user@googlegroups.com > <mailto:akka-user@googlegroups.com>. > Visit this group at http://groups.google.com/group/akka-user > <http://groups.google.com/group/akka-user>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.