[2.0.4] Setting File Upload Size Limit

370 views
Skip to first unread message

Jay Park

unread,
Nov 10, 2012, 1:24:06 PM11/10/12
to play-fr...@googlegroups.com
Hi everyone, 

Is it possible by now for Play to limit file upload size? I know in the past it was not possible. 

Thanks!

Jay

James Roper

unread,
Nov 12, 2012, 12:55:13 AM11/12/12
to play-fr...@googlegroups.com
Java or Scala?  In Scala it's always been possible.  If you want to limit the size of the whole request:

def myAction = Action(parse.maxLength(1024 * 1024, parse.multipartFormData)) { request =>
  ...
}

You can also limit individual parts, but that's a little more involved.

Jay Park

unread,
Nov 12, 2012, 2:06:34 AM11/12/12
to play-fr...@googlegroups.com
Hi James, 

I thought it is related to Netty's capability. I meant in Java. 
If it is not supported in Java, then I have no choice but to use a front-end web server to work around. 
But then I cannot expect full performance of my Play app because of the proxy, right?
Thanks!

Jay

James Roper

unread,
Nov 12, 2012, 7:05:33 PM11/12/12
to play-fr...@googlegroups.com
So @BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = 1024) doesn't work?

Or are you referring to the fact that Play doesn't terminate the connection early when the limit is reached?

Jay Park

unread,
Nov 13, 2012, 9:14:35 AM11/13/12
to play-fr...@googlegroups.com
It works because I can see browser stop uploading.
However, action does not return result. It looks like action is blocked or something. 

@BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = 1024 * 1024)
pulic static Result index() {
  if(request().body().isMaxSizeExceeded()) {
    return badRequest("Too much data!"); // this is not returned
  } else {
    ok("Got body: " + request().body().asText()); 
  }
}

S Barlow

unread,
Jan 7, 2013, 4:35:12 PM1/7/13
to play-fr...@googlegroups.com
I am seeing the same behaviour Jay. The upload http request is hanging but not terminated and the badRequest call hangs.
So at least the upload size restriction is observed. But not good behaviour.
Reply all
Reply to author
Forward
0 new messages