commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "shyamal" <shyam...@metalogicsystems.com>
Subject Problem parseRequest with commons fileupload
Date Tue, 20 Nov 2007 13:56:25 GMT
Hi,

I am trying to upload a small text file using commons/fileupload 1.2. I am
using NetBeans 5.5.1 with Bundled Tomcat 5.5.17.

Here is the HTML code:
Upload Page

The java code is here:

public class ourUpload extends HttpServlet {

    /** Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
                org.apache.commons.fileupload.disk.DiskFileItemFactory
factory = new org.apache.commons.fileupload.disk.DiskFileItemFactory();
        // maximum size that will be stored in memory
        factory.setSizeThreshold(4096);
        // the location for saving data that is larger than
getSizeThreshold()
        factory.setRepository(new File("/tmp"));
        org.apache.commons.fileupload.servlet.ServletFileUpload upload=null;
        List  fileItems = null;
  try
  {
         upload = new
org.apache.commons.fileupload.servlet.ServletFileUpload(factory);

        // maximum size before a FileUploadException will be thrown
        upload.setSizeMax(1000000);

          fileItems = upload.parseRequest(request);
        }
  catch(Exception e)
  {
      e.printStackTrace();
  }
         if (fileItems.size()==0)
        {
            out.println("Couldnot upload");
            return;
        }

        Iterator i = fileItems.iterator();
        String comment = ((FileItem)i.next()).getString();
        FileItem fi = (FileItem)i.next();
        // filename on the client
        String fileName = fi.getName();
        fi.write(new File("/www/uploads/", fileName));
        out.close();
    }

However, parseRequest is always returning a list with 0 items.
I am not using struts or any request wrappers.

Please Help!!!

Thanks a lot in advance

Shyamal


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message