commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "N G" <>
Subject FileItemIterator only has 1 part, dropping the rest of the file
Date Sun, 21 Dec 2008 18:08:16 GMT

I have the following code using FileUpload streaming. However,
probably due to my overlooking something, it only returns the 'while'
loop executes only once! That is, FileItemIterator returns true for
hasNext only once.

This causes only the first part of the file captured, dropping the rest.

Can someone point out what I am doing wrong here? The code is almost
verbatim from the apache site. I do want to point out that the file is
not very big. It's just a text file of size 6.6Kb.

private String getFileContent(HttpServletRequest request)
    throws IOException
    // Check that we have a file upload request
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    if (!isMultipart)
      String message = "Request must be multipart.";
      throw new IOException(message);

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();

    // Initialize string content
    StringBuilder content = new StringBuilder();

      // Parse the request
      FileItemIterator iter = upload.getItemIterator(request);
      int i = 0;
      while (iter.hasNext())
        FileItemStream item =;
        InputStream stream = item.openStream();
        byte[] fileBytes = new byte[stream.available()];;

        String tempContent = new String(fileBytes);
    catch (FileUploadException e)

    return content.toString();


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message