You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jfc <jf...@btopenworld.com> on 2002/10/04 23:46:21 UTC

enforcing max upload file size - before its too late!

Hi,

I have implemented the functionality for file uploads as demonstrated in 
struts-upload.war however I have a question.

How could I implement the example such that the file is uploaded chunk 
by chunk thereby giving the server the opportunity of stopping the 
upload at a given max file upload size and redirecting to the error page.

Although I have a validation method on my form bean which has the 
FormFile as a property, it appears as though the file is uploaded in its 
entirety before the size is checked.

The obvious concern here is that someone might decide to upload a file 
the size of the internet to my server which would struggle to cope with 
such a large file.

Perhaps I am overlooking some simple fact to the way this upload works 
but I don't see a solution at the moment other than somehow uploading 
the file chunk by chunk.

Any advice is much appreciated.

Jfc


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: enforcing max upload file size - before its too late!

Posted by Thomas Eichberger <we...@java.at>.
Hi,

here is my piece of source code for that problem:


stream = file.getInputStream();

zipFile = new File( user.path, user.kurzname + "-upload.zip" );
bos = new BufferedOutputStream( new FileOutputStream( zipFile ) );

int bytesRead = 0;
int count = 0;
byte[] buffer = new byte[ 8192 ];
while ( ( bytesRead = stream.read( buffer, 0, 8192 ) ) != -1 )
{
bos.write(buffer, 0, bytesRead);
count += bytesRead;

         if ( count > 2000000 ) // THIS IS THE MAXIMUM SIZE
         {
         errors.add(ActionErrors.GLOBAL_ERROR,
         new ActionError( "error.upload.file" ) );
         return mapping.findForward( "failure" );
         }
         }


And I have a finally block surrounding this where I close all streams :-)


Thomas




At 17:58 06.10.2002 +0000, jfc wrote:
>jfc wrote:
>
>>Hi,
>>
>>I have implemented the functionality for file uploads as demonstrated in 
>>struts-upload.war however I have a question.
>>
>>How could I implement the example such that the file is uploaded chunk by 
>>chunk thereby giving the server the opportunity of stopping the upload at 
>>a given max file upload size and redirecting to the error page.
>>
>>Although I have a validation method on my form bean which has the 
>>FormFile as a property, it appears as though the file is uploaded in its 
>>entirety before the size is checked.
>>
>>The obvious concern here is that someone might decide to upload a file 
>>the size of the internet to my server which would struggle to cope with 
>>such a large file.
>>
>>Perhaps I am overlooking some simple fact to the way this upload works 
>>but I don't see a solution at the moment other than somehow uploading the 
>>file chunk by chunk.
>>
>>Any advice is much appreciated.
>>
>>Jfc
>>
>>
>>--
>>To unsubscribe, e-mail:
>><ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>I have to believe this has been covered before but I can find no previous 
>posts which answer the question. Any takers?
>
>Chees
>jfc
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: enforcing max upload file size - before its too late!

Posted by jfc <jf...@btopenworld.com>.
jfc wrote:

> Hi,
>
> I have implemented the functionality for file uploads as demonstrated 
> in struts-upload.war however I have a question.
>
> How could I implement the example such that the file is uploaded chunk 
> by chunk thereby giving the server the opportunity of stopping the 
> upload at a given max file upload size and redirecting to the error page.
>
> Although I have a validation method on my form bean which has the 
> FormFile as a property, it appears as though the file is uploaded in 
> its entirety before the size is checked.
>
> The obvious concern here is that someone might decide to upload a file 
> the size of the internet to my server which would struggle to cope 
> with such a large file.
>
> Perhaps I am overlooking some simple fact to the way this upload works 
> but I don't see a solution at the moment other than somehow uploading 
> the file chunk by chunk.
>
> Any advice is much appreciated.
>
> Jfc
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>
I have to believe this has been covered before but I can find no 
previous posts which answer the question. Any takers?

Chees
jfc



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>