Zoran,

I'm on Struts v1.2.4 and it works as specified. Here is an outline of the
key points I followed:

1) Made sure my <html:form ... /> includes enctype="multipart/form-data"

2) Make sure my ActionForm subClass contains a private property of the  type
org.apache.struts.upload.FormFile with the appropriate get/set methods. That
isn't a class but an Interface used by the MultiPartRequestHandler to keep
thing simple for you.

3) Use the html file tag: <html:file property="zip" />

Where "zip" was my property (I'm uploading a .zip file) and getZip() and
setZip() are my getter and setter, respectively.

4) Check in my Action's appropriate execute method for the existence of the
attribute you mentioned below.  I do that like so:

// MultiPartRequestHandler is of class:
// org.apache.struts.upload.MultipartRequestHandler

Boolean b = (Boolean)
request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
if ( b != null ) {
        // You exceeded your Struts controller's
        // "maxFileSize" for uploads so let the
        // user know the upload was too large!
}

How did I test this?  By setting my struts-config.xml file's controller
section and using a 10k .zip file:

a) <controller maxFileSize="2K" />

The boolean existed because my zip file was larger then that specified 2K
limit.

b) <controller maxFileSize="2M" />

The boolean didn't exist because my zip file was under 2M in size.  I could
then read the file's name using my get method to obtain the FormFile object
and using it's getFileName() method.  Like so: getZip().getFileName();
However, in practice you probably want to make sure a file was loaded before
you try to call that method or BOOM - exception, probably a
NullPointerException.

Regards,
David

-----Original Message-----
From: Zoran Avtarovski [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 23, 2004 9:12 AM
To: Struts Users Mailing List
Subject: File Upload Limits


I'm trying to find some detailed information on how to use the file size
limits using the struts MultipartRequestHandler. In the past I have used a
custom servlet, but I thought it was time to bring this into the struts
world.

Before anybody says anything, I tried to search the list archive but it says
it can't be searched.

So anyway I looked at the fileupload example, and have done the following:

Added the controller element
<controller maxFileSize="2M" inputForward="true" />

To my struts-config and in my UploadForm validate action I check the boolean
request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);

I take it from this that the requesthandler sets a boolean value in the
request if the file is greater in size than specified in the controller
element.

The problem is that this isn't working.

Any help would be appreciated.

Zoran



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to