Zoran Avtarovski wrote:
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
The CommonsMultipartRequestHandler in the struts package uses the commons upload classes FileItem, DiskFileUpload and FileUploadException. None of the other classes in the struts package reference either commons upload classes or CommonsMultipartRequestHandler. The CommonsMultipartRequestHandler is a default implementation of the struts MultipartRequestHandler used in the examples UploadForm extension of ActionForm. I personally think an implementation of a subclass of MultipartIterator in strust is more useful. But, whatever, I don't use the Struts solution. I think, further, that this is a prime example of code bloat in struts. This sort of thing should be readily available, of course, but it does not belong in the framework itself, in my opinion. This is, I think, a poor application and will have to be maintained despite many better soutions bound to come. I think my application itself is better and it will, no doubt, be eclipsed too.
Michael McGrady
Anyway, you can set your file size maximum, if that is what you want, using whatever implementation of Struts you conjure. If you use the commons implementation, it is not the other way around, then you can use the commons stuff something like as follows:
import org.apache.commons.fileupload.DiskFileUpload; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException;
import com.crackwillow.app.load.upload.UploadFileItem; import com.crackwillow.app.load.upload.UploadConstant; import com.crackwillow.log.StdOut;
public class UploadParser {
public UploadParser() { }
public void request(HttpServletRequest req, Vector uploadListeners, int fileSizeLimit, Hashtable parameters, Hashtable files, String tmpFolder, String encoding) throws IOException {
DiskFileUpload diskFileUpload = new DiskFileUpload(); diskFileUpload.setSizeMax(fileSizeLimit); diskFileUpload.setSizeThreshold(UploadConstant.MEMORY_BUFFER_SIZE); diskFileUpload.setRepositoryPath(tmpFolder);
if(encoding != null) { diskFileUpload.setHeaderEncoding(encoding); }
List list = null;
try { list = diskFileUpload.parseRequest(req); } catch(FileUploadException fileuploadexception) { throw new IOException(fileuploadexception.getMessage()); }
Object obj = null;
for(Iterator iterator = list.iterator(); iterator.hasNext();) {
'Hope this is helpful.
Michael McGrady
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]