You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by St...@bahn.de on 2003/11/19 18:07:40 UTC

FileUpload: restrict upload file size for any file, not just for the wholerequest

Hi,

we want to restrict the size of each *file* that is getting uploaded to
some maximum file size. The FileUpload lib only allows to set a maximum
*request* size.

Of course, I could use item.getSize() after the upload/parsing has finished
and then only process files that are below the max file size; and drop all
other files. However, we don't even want to upload files that are too
large. That is, we want to stop uploading a file when it turns out to be
larger than allowed and go on with the next file.

FileUpload contains a class ThresholdingOutputStream that can be used to
implement a stream that counts the bytes that are getting uploaded, i.e.
written to the output stream, and reacts when the threshold (max file size)
is reached.
So I just have to throw some exception in the implementation of the
abstract method thresholdReached() of ThresholdingOutputStream.

The problem is that in FileUploadBase::parseRequest(...), where this
exceptions ends up, there is no exception handling for exceptions (runtime
exceptions) that disallow processing of just *one* file item, not of the
*whole* request.
Thus, without patching FileUploadBase, I cannot restrict the size on a
per-file-basis.

Also, it would be helpful if the threshold in ThresholdingOutputStream had
type long instead of type int - for large file sizes... :-)

Would these be reasonable changes to the file upload lib?

Thanks,

Steffi
____________________________________________________
Internetauftritt der Deutschen Bahn AG >> http://www.bahn.de

---------

Diese E-Mail könnte  vertrauliche und/oder rechtlich geschützte
Informationen enthalten. Wenn Sie nicht der richtige Adressat sind oder
diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die
unbefugte Weitergabe dieser Mail sind nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.

----------



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: FileUpload: restrict upload file size for any file, not just for the wholerequest

Posted by Martin Cooper <ma...@apache.org>.
Bugzilla #20838 is an existing enhancement request that I believe covers
what you are suggesting. Feel free to add yourself to the 'cc' list if
you'd like to be kept up to date with this.

With regard to the use of 'int' versus 'long', there was a reason for
that, related to what is actually available via the underlying Java API.
However, I don't recall the exact issue right now. Feel free to enter a
new enhancement request, if you like. That will ensure that it at least
gets explained somewhere. ;-)

--
Martin Cooper


On Wed, 19 Nov 2003 Steffi.Rauschenbach@bahn.de wrote:

> Hi,
>
> we want to restrict the size of each *file* that is getting uploaded to
> some maximum file size. The FileUpload lib only allows to set a maximum
> *request* size.
>
> Of course, I could use item.getSize() after the upload/parsing has finished
> and then only process files that are below the max file size; and drop all
> other files. However, we don't even want to upload files that are too
> large. That is, we want to stop uploading a file when it turns out to be
> larger than allowed and go on with the next file.
>
> FileUpload contains a class ThresholdingOutputStream that can be used to
> implement a stream that counts the bytes that are getting uploaded, i.e.
> written to the output stream, and reacts when the threshold (max file size)
> is reached.
> So I just have to throw some exception in the implementation of the
> abstract method thresholdReached() of ThresholdingOutputStream.
>
> The problem is that in FileUploadBase::parseRequest(...), where this
> exceptions ends up, there is no exception handling for exceptions (runtime
> exceptions) that disallow processing of just *one* file item, not of the
> *whole* request.
> Thus, without patching FileUploadBase, I cannot restrict the size on a
> per-file-basis.
>
> Also, it would be helpful if the threshold in ThresholdingOutputStream had
> type long instead of type int - for large file sizes... :-)
>
> Would these be reasonable changes to the file upload lib?
>
> Thanks,
>
> Steffi
> ____________________________________________________
> Internetauftritt der Deutschen Bahn AG >> http://www.bahn.de
>
> ---------
>
> Diese E-Mail könnte  vertrauliche und/oder rechtlich geschützte
> Informationen enthalten. Wenn Sie nicht der richtige Adressat sind oder
> diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
> Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die
> unbefugte Weitergabe dieser Mail sind nicht gestattet.
>
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and destroy this e-mail. Any
> unauthorised copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
>
> ----------
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: FileUpload: restrict upload file size for any file, not just for the wholerequest

Posted by Schalk <sc...@volume4.co.za>.
I would recommend submitting this as a future enhancement request, or
develop a add-on and submit it for inclusion in the next release.

Kind Regards
Schalk Neethling
Web Developer.Designer.Programmer.CEO
Volume4.Development.Multimedia.Branding
emotionalize.conceptualize.visualize.realize
Tel: +27125468436
Fax: +27125468436
email:schalk@volume4.co.za
web: www.volume4.co.za
 
This message contains information that is considered to be sensitive or
confidential and may not be forwarded or disclosed to any other party
without the permission of the sender. If you received this message in error,
please notify me immediately so that I can correct and delete the original
email. Thank you. 

:: -----Original Message-----
:: From: Steffi.Rauschenbach@bahn.de [mailto:Steffi.Rauschenbach@bahn.de]
:: Sent: Wednesday, November 19, 2003 7:08 PM
:: To: commons-user@jakarta.apache.org
:: Subject: FileUpload: restrict upload file size for any file, not just for
the wholerequest
:: 
:: Hi,
:: 
:: we want to restrict the size of each *file* that is getting uploaded to
:: some maximum file size. The FileUpload lib only allows to set a maximum
:: *request* size.
:: 
:: Of course, I could use item.getSize() after the upload/parsing has
finished
:: and then only process files that are below the max file size; and drop
all
:: other files. However, we don't even want to upload files that are too
:: large. That is, we want to stop uploading a file when it turns out to be
:: larger than allowed and go on with the next file.
:: 
:: FileUpload contains a class ThresholdingOutputStream that can be used to
:: implement a stream that counts the bytes that are getting uploaded, i.e.
:: written to the output stream, and reacts when the threshold (max file
size)
:: is reached.
:: So I just have to throw some exception in the implementation of the
:: abstract method thresholdReached() of ThresholdingOutputStream.
:: 
:: The problem is that in FileUploadBase::parseRequest(...), where this
:: exceptions ends up, there is no exception handling for exceptions
(runtime
:: exceptions) that disallow processing of just *one* file item, not of the
:: *whole* request.
:: Thus, without patching FileUploadBase, I cannot restrict the size on a
:: per-file-basis.
:: 
:: Also, it would be helpful if the threshold in ThresholdingOutputStream
had
:: type long instead of type int - for large file sizes... :-)
:: 
:: Would these be reasonable changes to the file upload lib?
:: 
:: Thanks,
:: 
:: Steffi
:: ____________________________________________________
:: Internetauftritt der Deutschen Bahn AG >> http://www.bahn.de
:: 
:: ---------
:: 
:: Diese E-Mail könnte  vertrauliche und/oder rechtlich geschützte
:: Informationen enthalten. Wenn Sie nicht der richtige Adressat sind oder
:: diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
:: Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die
:: unbefugte Weitergabe dieser Mail sind nicht gestattet.
:: 
:: This e-mail may contain confidential and/or privileged information. If
you
:: are not the intended recipient (or have received this e-mail in error)
:: please notify the sender immediately and destroy this e-mail. Any
:: unauthorised copying, disclosure or distribution of the material in this
:: e-mail is strictly forbidden.
:: 
:: ----------
:: 
:: 
:: 
:: ---------------------------------------------------------------------
:: To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
:: For additional commands, e-mail: commons-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org