[2.0.*-scala] set up multipartFormData upload size limit

672 views
Skip to first unread message

mrak

unread,
Aug 9, 2012, 7:12:04 AM8/9/12
to play-fr...@googlegroups.com
I'd like to set up a file upload size limit to 500kB in Play 2.

I'm currently using multipartFormData parser.

I'm really struggling with it. I've tried all different application.conf settings but nothing would actually kick in and I'm still able to submit a 500MB files (prolly even more).

If not for a body parser then perhaps there is a global netty setting for 2.0 that would actually work? The bottom line is that I don't want the input stream to be fully read in mem/tempfile unless size validation passes ok. 

thanks,
mrak

Sadache Aldrobi

unread,
Aug 9, 2012, 8:18:21 AM8/9/12
to play-fr...@googlegroups.com
Can you please provide an example of what you are trying to do?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/o54qUAS207kJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



--
www.sadekdrobi.com
ʎdoɹʇuǝ

mrak

unread,
Aug 9, 2012, 8:56:59 AM8/9/12
to play-fr...@googlegroups.com
there is really not much to it, take the example from Play Scala tutorial

def upload = Action(parse.multipartFormData) { request =>
  request.body.file("picture").map { picture =>
    import java.io.File
    val filename = picture.filename 
    val contentType = picture.contentType
    picture.ref.moveTo(new File("/tmp/picture"))
    Ok("File uploaded")
  }.getOrElse {
    Redirect(routes.Application.index).flashing(
      "error" -> "Missing file"
    )
  
}

I need to set a max limit of the uploaded multipart. This or set some low level netty limit. Either way I'd need to be able to handle the error somehow, or at least have 413 returned by Play.

cheers
Message has been deleted

Andreas Taube

unread,
Aug 9, 2012, 2:47:41 PM8/9/12
to play-fr...@googlegroups.com
Have a look at the BodyParser

Here you can specify a max content length:
// Accept only 10KB of data.
def save = Action(parse.text(maxLength = 1024 * 10)) { request =>
  Ok("Got: " + text)
}

You can also set a default length in the application.conf
parsers.text.maxLength=128K

Zoro

unread,
Jun 2, 2014, 11:15:08 AM6/2/14
to play-fr...@googlegroups.com, taub...@gmail.com
Andreas Taube, i looked BodyParser documentation, but you can't set maxLength for multipartFormData.

I also looking for the answer to this question.  Anyone can help?
Reply all
Reply to author
Forward
0 new messages