You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Henrique Boregio <hb...@gmail.com> on 2011/03/18 03:59:52 UTC
FileUpload size limit
Hi, how can I restrict the size of a file being uploaded, before it gets
uploaded?
The following code does not work, since wicket first uploads the file to the
server, THEN checks its size (I've tried it uploading a 1Gig file):
protected void onSubmit() {
final FileUpload upload = fileUploadField.getFileUpload();
if (upload != null) {
if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
return;
}
}
}
I've also tried setting the form's maxSize like so, but the file still seems
to get uploaded:
setMaxSize(Bytes.kilobytes(150));
Anyone run into this same problem? Thanks.
Re: FileUpload size limit
Posted by Attila Király <ki...@gmail.com>.
Hi,
The sad answer is that you can not prevent the actual data transfer between
the browser and the server. The core problem is that all browsers of today
will only read the response after the request has been fully written out.
This means that even if you know the size from the content-length and you
know that you do not want to process the inputstream at all, the data will
still be sent by the browser and the servlet container will still have to
read and skip it.
The only exception to this is a new settings in tomcat 7.0.11:
"swallowAbortedUploads" (see [1]). If you disable this (default is true)
Tomcat will not read the request body if the application set a 413 response
(request entity too large). This is quick and prevents the data transfer but
all browsers treat it as an aborted connection during request sending (and
they do not care about the response already sitting there at their sockets)
and they show a big error page.
However this can probably still be worked around if you target a hidden
iframe with the upload form. So if the file is big and tomcat closes the
connection the error is loaded into the iframe and it is not shown to the
user. Maybe this could be integrated into the wicket-ajax-multipart-upload
functionality but currently it is not. I would definitely like it (and I
already opened an improvement issue not long ago about this, see [2]).
[1] "swallowAbortedUploads":
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
[2] https://issues.apache.org/jira/browse/WICKET-3525
<http://tomcat.apache.org/tomcat-7.0-doc/config/context.html>Attila
2011/3/18 Henrique Boregio <hb...@gmail.com>
> Hi, how can I restrict the size of a file being uploaded, before it gets
> uploaded?
>
> The following code does not work, since wicket first uploads the file to
> the
> server, THEN checks its size (I've tried it uploading a 1Gig file):
>
> protected void onSubmit() {
>
> final FileUpload upload = fileUploadField.getFileUpload();
>
> if (upload != null) {
> if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> return;
> }
> }
> }
>
>
> I've also tried setting the form's maxSize like so, but the file still
> seems
> to get uploaded:
> setMaxSize(Bytes.kilobytes(150));
>
> Anyone run into this same problem? Thanks.
>
Re: FileUpload size limit
Posted by Attila Király <ki...@gmail.com>.
You are right, these special cases should not be in wicket core if they can
be implemented separately.
In this case the FileReader API could be used to do client side javascript
based size checking. It is interesting to me so I will probably make a new
class for it in wicketstuff/html5. I think it can be done in a way so it is
used when FileReader API is available but cause no trouble if it is not (so
it works in all browsers and IEs).
Attila
2011/3/18 Martin Grigorov <mg...@apache.org>
> On Fri, Mar 18, 2011 at 3:53 PM, Attila Király <kiralyattila.hu@gmail.com
> >wrote:
>
> > That will be the HTML5 FileReader Api. Too bad it is not supported in IE9
> > and Opera. But it would awesome to see wicket support for that because it
> > would give a better user experience in Chrome and FF.
> >
>
> Attila, you know that I don't use Windows/IE but Wicket as web framework
> should support it. Even the ancient IE6 ...
> We don't even use XMLHttpRequest v.2 capabilities to upload files and
> provide progress but use iframe for ajax uploads for this reason.
> To keep it simple we don't like to add branches in the code for upload in
> FF/Chrome and the rest.
>
> At least it is easy to override wicket-ajax.js with monkey patch and use
> the
> newest technologies if your users agree on that.
>
> >
> > Attila
> >
> > 2011/3/18 John Owen <jo...@globalscape.com>
> >
> > > There are some javascript-based solutions that can check the file info
> > > (size, extensions, etc.) before transmitting the file(s). The downside
> is
> > > that they don't work in IE (up to IE 8).
> > >
> > > The example I found most useful is here:
> http://valums.com/ajax-upload/
> > >
> > > Regards
> > >
> > > -----Original Message-----
> > > From: Henrique Boregio [mailto:hboregio@gmail.com]
> > > Sent: Thursday, March 17, 2011 10:00 PM
> > > To: users@wicket.apache.org
> > > Subject: FileUpload size limit
> > >
> > > Hi, how can I restrict the size of a file being uploaded, before it
> gets
> > > uploaded?
> > >
> > > The following code does not work, since wicket first uploads the file
> to
> > > the
> > > server, THEN checks its size (I've tried it uploading a 1Gig file):
> > >
> > > protected void onSubmit() {
> > >
> > > final FileUpload upload = fileUploadField.getFileUpload();
> > >
> > > if (upload != null) {
> > > if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> > > return;
> > > }
> > > }
> > > }
> > >
> > >
> > > I've also tried setting the form's maxSize like so, but the file still
> > > seems
> > > to get uploaded:
> > > setMaxSize(Bytes.kilobytes(150));
> > >
> > > Anyone run into this same problem? Thanks.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > > For additional commands, e-mail: users-help@wicket.apache.org
> > >
> > >
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com <http://jweekend.com/>
>
Re: FileUpload size limit
Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Mar 18, 2011 at 3:53 PM, Attila Király <ki...@gmail.com>wrote:
> That will be the HTML5 FileReader Api. Too bad it is not supported in IE9
> and Opera. But it would awesome to see wicket support for that because it
> would give a better user experience in Chrome and FF.
>
Attila, you know that I don't use Windows/IE but Wicket as web framework
should support it. Even the ancient IE6 ...
We don't even use XMLHttpRequest v.2 capabilities to upload files and
provide progress but use iframe for ajax uploads for this reason.
To keep it simple we don't like to add branches in the code for upload in
FF/Chrome and the rest.
At least it is easy to override wicket-ajax.js with monkey patch and use the
newest technologies if your users agree on that.
>
> Attila
>
> 2011/3/18 John Owen <jo...@globalscape.com>
>
> > There are some javascript-based solutions that can check the file info
> > (size, extensions, etc.) before transmitting the file(s). The downside is
> > that they don't work in IE (up to IE 8).
> >
> > The example I found most useful is here: http://valums.com/ajax-upload/
> >
> > Regards
> >
> > -----Original Message-----
> > From: Henrique Boregio [mailto:hboregio@gmail.com]
> > Sent: Thursday, March 17, 2011 10:00 PM
> > To: users@wicket.apache.org
> > Subject: FileUpload size limit
> >
> > Hi, how can I restrict the size of a file being uploaded, before it gets
> > uploaded?
> >
> > The following code does not work, since wicket first uploads the file to
> > the
> > server, THEN checks its size (I've tried it uploading a 1Gig file):
> >
> > protected void onSubmit() {
> >
> > final FileUpload upload = fileUploadField.getFileUpload();
> >
> > if (upload != null) {
> > if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> > return;
> > }
> > }
> > }
> >
> >
> > I've also tried setting the form's maxSize like so, but the file still
> > seems
> > to get uploaded:
> > setMaxSize(Bytes.kilobytes(150));
> >
> > Anyone run into this same problem? Thanks.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>
Re: FileUpload size limit
Posted by Attila Király <ki...@gmail.com>.
That will be the HTML5 FileReader Api. Too bad it is not supported in IE9
and Opera. But it would awesome to see wicket support for that because it
would give a better user experience in Chrome and FF.
Attila
2011/3/18 John Owen <jo...@globalscape.com>
> There are some javascript-based solutions that can check the file info
> (size, extensions, etc.) before transmitting the file(s). The downside is
> that they don't work in IE (up to IE 8).
>
> The example I found most useful is here: http://valums.com/ajax-upload/
>
> Regards
>
> -----Original Message-----
> From: Henrique Boregio [mailto:hboregio@gmail.com]
> Sent: Thursday, March 17, 2011 10:00 PM
> To: users@wicket.apache.org
> Subject: FileUpload size limit
>
> Hi, how can I restrict the size of a file being uploaded, before it gets
> uploaded?
>
> The following code does not work, since wicket first uploads the file to
> the
> server, THEN checks its size (I've tried it uploading a 1Gig file):
>
> protected void onSubmit() {
>
> final FileUpload upload = fileUploadField.getFileUpload();
>
> if (upload != null) {
> if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> return;
> }
> }
> }
>
>
> I've also tried setting the form's maxSize like so, but the file still
> seems
> to get uploaded:
> setMaxSize(Bytes.kilobytes(150));
>
> Anyone run into this same problem? Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
RE: FileUpload size limit
Posted by John Owen <jo...@globalscape.com>.
There are some javascript-based solutions that can check the file info (size, extensions, etc.) before transmitting the file(s). The downside is that they don't work in IE (up to IE 8).
The example I found most useful is here: http://valums.com/ajax-upload/
Regards
-----Original Message-----
From: Henrique Boregio [mailto:hboregio@gmail.com]
Sent: Thursday, March 17, 2011 10:00 PM
To: users@wicket.apache.org
Subject: FileUpload size limit
Hi, how can I restrict the size of a file being uploaded, before it gets
uploaded?
The following code does not work, since wicket first uploads the file to the
server, THEN checks its size (I've tried it uploading a 1Gig file):
protected void onSubmit() {
final FileUpload upload = fileUploadField.getFileUpload();
if (upload != null) {
if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
return;
}
}
}
I've also tried setting the form's maxSize like so, but the file still seems
to get uploaded:
setMaxSize(Bytes.kilobytes(150));
Anyone run into this same problem? Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: FileUpload size limit
Posted by Pedro Santos <pe...@gmail.com>.
>
>
>> I've also tried setting the form's maxSize like so, but the file still
>> seems
>> to get uploaded:
>> setMaxSize(Bytes.kilobytes(150));
>>
>
weird, LimitedInputStream should be enough, are u using UploadWebRequest?
>
>> Anyone run into this same problem? Thanks.
>>
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>
--
Pedro Henrique Oliveira dos Santos
Re: FileUpload size limit
Posted by Pedro Santos <pe...@gmail.com>.
Set Form#setMaxSize and Wicket will use an LimitedInputStream which limits
its data size
On Thu, Mar 17, 2011 at 11:59 PM, Henrique Boregio <hb...@gmail.com>wrote:
> Hi, how can I restrict the size of a file being uploaded, before it gets
> uploaded?
>
> The following code does not work, since wicket first uploads the file to
> the
> server, THEN checks its size (I've tried it uploading a 1Gig file):
>
> protected void onSubmit() {
>
> final FileUpload upload = fileUploadField.getFileUpload();
>
> if (upload != null) {
> if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> return;
> }
> }
> }
>
>
> I've also tried setting the form's maxSize like so, but the file still
> seems
> to get uploaded:
> setMaxSize(Bytes.kilobytes(150));
>
> Anyone run into this same problem? Thanks.
>
--
Pedro Henrique Oliveira dos Santos
Re: FileUpload size limit
Posted by Attila Király <ki...@gmail.com>.
The "maxPostSize" setting in tomcat is not playing any role in file uploads
(multipart requests) because these requests are processed by the web
application directly. So this should be configured with wicket settings like
IApplicationSettings. setDefaultMaximumUploadSize() and Form.setMaxSize().
But the browser will sadly send the file anyway.
Attila
2011/3/18 Bruno Borges <br...@gmail.com>
> I guess you should consider configuring your container properly:
>
>
> http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat
>
> <
> http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat
> >
> Cheers,
>
> Bruno Borges
> www.brunoborges.com.br
> +55 21 76727099
>
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
> - Francois de La Rochefoucauld
>
>
>
> On Thu, Mar 17, 2011 at 11:59 PM, Henrique Boregio <hboregio@gmail.com
> >wrote:
>
> > Hi, how can I restrict the size of a file being uploaded, before it gets
> > uploaded?
> >
> > The following code does not work, since wicket first uploads the file to
> > the
> > server, THEN checks its size (I've tried it uploading a 1Gig file):
> >
> > protected void onSubmit() {
> >
> > final FileUpload upload = fileUploadField.getFileUpload();
> >
> > if (upload != null) {
> > if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> > return;
> > }
> > }
> > }
> >
> >
> > I've also tried setting the form's maxSize like so, but the file still
> > seems
> > to get uploaded:
> > setMaxSize(Bytes.kilobytes(150));
> >
> > Anyone run into this same problem? Thanks.
> >
>
Re: FileUpload size limit
Posted by Bruno Borges <br...@gmail.com>.
I guess you should consider configuring your container properly:
http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat
<http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat>
Cheers,
Bruno Borges
www.brunoborges.com.br
+55 21 76727099
"The glory of great men should always be
measured by the means they have used to
acquire it."
- Francois de La Rochefoucauld
On Thu, Mar 17, 2011 at 11:59 PM, Henrique Boregio <hb...@gmail.com>wrote:
> Hi, how can I restrict the size of a file being uploaded, before it gets
> uploaded?
>
> The following code does not work, since wicket first uploads the file to
> the
> server, THEN checks its size (I've tried it uploading a 1Gig file):
>
> protected void onSubmit() {
>
> final FileUpload upload = fileUploadField.getFileUpload();
>
> if (upload != null) {
> if(upload.getSize() > Bytes.kilobytes(150).bytes()) {
> return;
> }
> }
> }
>
>
> I've also tried setting the form's maxSize like so, but the file still
> seems
> to get uploaded:
> setMaxSize(Bytes.kilobytes(150));
>
> Anyone run into this same problem? Thanks.
>