title: Java - Commons-fileupload.jar - Problem
body: <p>I am trying to upload a file using <code>commons-fileupload-1.1.1.jar</code> file (I know it is not the latest version but it comes with <code>struts 1.3.10</code> so I am using the same).</p>
  
  <p>Now the problem is when I parse the <code>request</code> (HttpServletRequest) to get a <code>List</code> of <code>FileItem</code>s, I am getting an empty list.</p>
  
  <pre><code>        DiskFileItemFactory factory = new DiskFileItemFactory();
  
          File tempDir = new File("/fileUploadDirectory");
          tempDir.mkdir();
  
          // Set factory constraints
          factory.setSizeThreshold(10000);
          factory.setRepository(tempDir);
  
          // Create a new file upload handler
          ServletFileUpload upload = new ServletFileUpload(factory);
  
          // Set overall request size constraint
          upload.setSizeMax(10000);
  
          // Parse the request
          List items = upload.parseRequest(request);
          System.out.println(items);
  
          System.out.println(request.getContentLength());
  
          // Process the uploaded items
          Iterator&lt;FileItem&gt; iter = items.iterator();
          while (iter.hasNext()) {
              FileItem item = iter.next();
              if (item.isFormField()) {
                  System.out.println("File is a FormField");
              } else {
                  System.out.println("File is a File");
              }
          } 
  </code></pre>
  
  <p>Q1. Why I am getting an empty list?</p>
  
  <p>When I am printing the size of the request by <code>request.getContentLength()</code> (as shown above in the code), I get some numerical data (1536) which I think is showing the length of the file. If it is showing the length of the file, then why I am not getting list of <code>FileItem</code>s?</p>
  
  <p><b>Note:</b> I am using it with <code>Struts 1.3.10</code> with <code>ActionForm</code>. Is is creating any problem.</p>
  
  <p><b>Note:</b> I am also not getting any exception while parsing the request.</p>