Hi David,
Let me get this straight. By using the way you described, if the file to upload exceeds maximum allowable size, then no upload will be proceeded right?
I only know how to upload the stupid way, i.e. upload the whole file and abort if file size exceeds maximum.
Thanks
----- Original Message ----- From: "David G. Friedman" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, September 24, 2004 7:45 PM
Subject: RE: File Upload Limits
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
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]