I'm using a Struts ActionForm to upload a file using a "multipart/enc"
POST.  The files being uploaded are sometimes rather large and we
wish to restrict them to ... 5 to 10 megs.

Currently we are doing this:
--- inside the effected tile
<html:form method="post" action="/processUploadAction" 
enctype="multipart/form-data">
    <html:file property="attachment" accesskey="f"/>
...
</html:form>


---  inside execute() for Action processUploadAction
...
        final FormFile attachment    = uploadForm.getAttachment();
        int attachSize                      = attachment.getFileSize();
        if (attachSize > MAXATTACHSIZE){
            actionErrors.add("error.attach.toobig");
            return request.findForward("fail");
        }
...


Now the issue with this occurs when a user uploads a large file.  Let's say
they are uploading a 90 megabyte file.  This takes 30 minutes.  Our
session timeout is set to 25 minutes.  The user is logged out, we
get errors, and the operation fails miserably.

The ideal situation would allow for me to detect the file upload size
before the user uploads, and before they time out.

The following issues prevent me from being able to exhibit the ideal
situation:

1.)  By the time I have reached the action the post has already
taken place.

2.)  Even in the ActionForm.validate method,  I can't see the
size of the file before it has been uploaded.

3.)  Using the controller setting, "max-file-size" seems the viable means
to handle this, but unfortunately, this seems to still not restrict the
established rule before the file has been completely uploaded. 
Additionally,
it is not clear to me as to what the controller does when this max-file-size
threshold is reached -- how do I intelligently produce an error before
my action is touched?


Ideally, what should be happening is we should be able to detect
how large the file being uploaded is before the post even occurs.
For example, we could look at "request.getContentLength()" and
do something smart based on that.


Essentially, it looks as though I may have to create a custom request
processor for my purposes because the existing functionality
afforded by the Controller is inadequate for our designs.  I wish to
make sure that this is the case.  If this is the case I take it I should
start with writing an extended RequestProcessor class that overrides
the processPreprocess method and then performs operations on the
actual parameters/request object to make sure the content length
is short enough.

Any thoughts and help is appreciated.
------------------------------------------------------------------
Gregory Class <http://gregoryclass.com>
Developer
Spam Arrest LLC <http://spamarrest.com> 

Reply via email to