I'm using Struts 1.1, and trying to use the commons file upload version
1 package (from http://jakarta.apache.org/commons/fileupload/index.html
) to handle

file upload request in my application, yet I seemed to always get an
empty List from the parseRequest function of the
org.apache.commons.fileupload.DiskFileUpload class, although the method
isMultiPartContent returns true!!!!

 

I am handling file uploads in a class name uploadAction, which extends
from org.apache.struts.action.Action class. Is it inappropriate to
implement the fileupload in a

Action subclass!?  If so, how should I go about solving the problem
using strut's ActionServlet/Action model and file upload packages
together!?

 

<html:form action="/upload" method="POST" enctype="multipart/form-data">

problem is I always get an empty fileItem list returned from
parseRequest(). I used this way as I didn't get struts uploader to work
just in memory and don't write on disk :(

 

 

The following is my uploadAction class:

 

package com.bat.upload.action;

 

import com.bat.common.action.BaseAction;

import com.bat.upload.form.UploadForm;

 

import java.io.*;

import java.util.*;

 

import javax.servlet.ServletException;

import javax.servlet.http.*;

 

import org.apache.struts.action.*;

import org.apache.commons.fileupload.*;

 

 

public class UploadAction extends BaseAction

{

    public UploadAction()

    {

    }

    public ActionForward perform(ActionMapping mapping, ActionForm f,
HttpServletRequest request, HttpServletResponse response)

        throws IOException, ServletException

    {

 

    try

       {

        // returns true 

        boolean isMultipart = FileUpload.isMultipartContent( request );

 

 

 

        DiskFileUpload fu = new DiskFileUpload();

        // maximum size before a FileUploadException will be thrown

        fu.setSizeMax(10000000);

 

 

        // maximum size that will be stored in memory

        fu.setSizeThreshold(2000000);

 

          List fileItems = fu.parseRequest(request);

 

          // Empty iterator received

          Iterator i = fileItems.iterator();

          while ( i.hasNext() )

          {

            FileItem fileItem = (FileItem)i.next();

            if ( fileItem.isFormField )

            {

                  // Do something

            } else {

                  // Do anotherthing

            }

          }

      return mapping.findForward( "upload_completed" );

    }

    catch(FileUploadException fue)

    {

      throw new ServletException("FileUploadError: " + fue.getMessage(),
fue);

    }

    catch(Exception e)

    {

      throw new ServletException("FileWriteError", e);

    }

  }     

  ActionForward forwardResult = new ActionForward(mapping.getInput());

  return forwardResult;

    }

}

 

 

Thanks, best regards

 

 

Reply via email to