You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Brian Coakley <br...@hotmail.com> on 2004/01/22 09:52:41 UTC

FileUpload problem/question

I've used the code right from the upload example and I get no results from upload.parseRequest(request);  There is other data on the page that is updating just fine.  Am I missing something obvious?  Thanks, Brian Coakley

      // Check that we have a file upload request
      boolean isMultipart = FileUpload.isMultipartContent(request);
      if(isMultipart){

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

        // Parse the request
        List /* FileItem */ items = upload.parseRequest(request);

        // Process the uploaded items
        Iterator iter = items.iterator();
        while (iter.hasNext()) {
          FileItem item = (FileItem) iter.next();

          if (item.isFormField()) {
            // Process a regular form field
            String name = item.getFieldName();
              String value = item.getString();
            } else {
            // Process a file upload
            String fieldName = item.getFieldName();
              fileName = item.getName();
              String contentType = item.getContentType();
              boolean isInMemory = item.isInMemory();
              long sizeInBytes = item.getSize();
            }
        }
      }


Re: FileUpload problem/question

Posted by Martin Cooper <ma...@apache.org>.
Is this in your own servlet, or in a Struts app, or where? If it's inside
Struts, then just remove it - Struts already handles file upload for you.
See the Struts documentation for the details.

--
Martin Cooper


On Thu, 22 Jan 2004, Brian Coakley wrote:

> I've used the code right from the upload example and I get no results from upload.parseRequest(request);  There is other data on the page that is updating just fine.  Am I missing something obvious?  Thanks, Brian Coakley
>
>       // Check that we have a file upload request
>       boolean isMultipart = FileUpload.isMultipartContent(request);
>       if(isMultipart){
>
>         // Create a new file upload handler
>         DiskFileUpload upload = new DiskFileUpload();
>
>         // Parse the request
>         List /* FileItem */ items = upload.parseRequest(request);
>
>         // Process the uploaded items
>         Iterator iter = items.iterator();
>         while (iter.hasNext()) {
>           FileItem item = (FileItem) iter.next();
>
>           if (item.isFormField()) {
>             // Process a regular form field
>             String name = item.getFieldName();
>               String value = item.getString();
>             } else {
>             // Process a file upload
>             String fieldName = item.getFieldName();
>               fileName = item.getName();
>               String contentType = item.getContentType();
>               boolean isInMemory = item.isInMemory();
>               long sizeInBytes = item.getSize();
>             }
>         }
>       }
>
>

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