1 Reply Latest reply on May 31, 2005 9:38 AM by roy.russo

    How to upload file with Portlet

    mico

      Hi all,
      I'm trying to upload a file into my portlet.
      I'm using commons-upload, but
      When I call parseRequest(actionRequest) method, it throw an Exception
      MULTIPART/FORM-BASED needed, founded application-www-urlencoded.


      But If I set the form with enctype MULTIPART-FORM-BASED, it does not process the request ?

      How can I upload my file with portlet ?
      Can anyone suggest the right code to accomplish this task?

      Thank You

        • 1. Re: How to upload file with Portlet

          Take a look at the AdminCMSPortlet. The upload.jsp has something like this:

          <form name="uploadform" method="post" enctype="multipart/form-data" action= ...


          Make sure you are using the most recent version of fileupload that allows for portlet fileuploads. Previous versions did not.

          The code you're looking for begins with this:

          DiskFileItemFactory factory = new DiskFileItemFactory();
           PortletFileUpload upload = new PortletFileUpload(factory); // TODO: configure uploader
           String sPath = "";
           List fileItems = upload.parseRequest(aReq); // TODO: mod interface to allow multiple uploads.
           Iterator itr = fileItems.iterator();
           while(itr.hasNext())
           {
           FileItem item = (FileItem) itr.next();