Multipart file upload with access to the file upload stream
1,608 views
Skip to first unread message
Rich V
unread,
May 24, 2012, 1:37:01 PM5/24/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
The out of the box multipart upload functionality in Play 2.0 allows access to the entire file after the upload is complete. The website I'm developing will require efficient uploads so this approach won't be appropriate for this specific case. I've read much of the Play 2.0 documentation that's online and found that the best approach to handling this is to write a custom body parser. The ScalaBodyParser documentation page lists some interesting examples but the code for them is nowhere to be found: A file body parser could store each chunk of bytes into a local file, and give a reference to the java.io.File as result (Iteratee[Array[Byte],File]).
A s3 body parser could push each chunk of bytes to Amazon S3 and give a the S3 object id as result (Iteratee[Array[Byte],S3ObjectId]).
I looked through the Play 2.0 source, specifically at the BodyParsers code and didn't find anything related to handling streams. I also searched Google extensively and couldn't find any examples. Can someone point me in the right direction for how to develop this, perhaps some sample code, a blog post, documentation, or github link? Any help is greatly appreciated. Thanks!
Joseph Burns
unread,
May 25, 2012, 8:29:18 AM5/25/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
I'd also be interested in this if anyone is able to show a snippet.
evaneus
unread,
Jun 4, 2012, 10:41:01 AM6/4/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
+1
Guillaume Bort
unread,
Jun 4, 2012, 10:55:18 AM6/4/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
You can use `parse.multipartFormData(myCustomFilePartHandler)` to do
that. You are right, the default file parts handler store files on
disk as temporary files. But by defining your own
`myCustomFilePartHandler` you can change that.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to play-fr...@googlegroups.com
There is very interesting presentation by Sadek and Guillaume in some
moment Sadek also describes how to ie. slow down the upload if needed
using Iteratee, in gerneral it's worth of watching from beginning to
the end.