Parse multipart/form-data in Java

1,897 views
Skip to first unread message

Magnus H

unread,
Jul 12, 2016, 10:50:22 AM7/12/16
to Akka User List
Hi,

I've been experimenting with posting data to an Akka-http server but I cannot figure out how to parse multipart/form-data. Basically I've got an HttpRequest and I want to get the posted data out from it, preferably one part at a time as a stream. If I post using "application/x-www-form-urlencoded" I've been able to unmarshall it using:

CompletionStage<akka.http.scaladsl.model.FormData> data = 
Unmarshaller.entityToUrlEncodedFormData().unmarshall(request.entity(), system.dispatcher(), mat);

However I haven't been able to figure out how to access the multipart unmarshaller and I have not been able to find any examples or any documentation about this for Java. 

I guess I could just get the raw data stream and parse it with Apache commons FileUpload API or similar but since I'm pretty sure there is a multipart unmarshaller in there somewhere it would be nice if I could just use that.

I'm using Akka 2.4.7. Any pointers would be appreciated.

Thanks,
Magnus

Marcelo Alves

unread,
Jul 12, 2016, 12:27:52 PM7/12/16
to Akka User List
Hello Magnus,
    You can use this code example  -> https://gist.github.com/jrudolph/08d0d28e1eddcd64dbd0 .. Its works well :)

--
>>>>>>>>>> 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+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Magnus H

unread,
Jul 13, 2016, 7:48:10 AM7/13/16
to Akka User List
Thank you Marcelo. 

Do you have any idea how to build that route using tha Java DSL?
Reply all
Reply to author
Forward
0 new messages