8 Replies Latest reply on Mar 29, 2006 5:10 AM by Andy Andy

    [HELP] File Upload Question

    Andy Andy Newbie

      Tools :JBoss 4.0.3sp1 + JBoss Portal 2.2

      In JBoss portal, there is a jsp to handle a user's file upload, and then it will can doView() in my portlet class.
      In my own portlet, I want to handle the upload file. But when I compile
      my .java class, there is an error as following:

      -------------------------------------------------------------------------------------
      [javac] D:\MIPS\web\nggAdminSite\portal2.2\nggDataExtractorPortlet\src\mips\nggDataExtractor\portlet\NGGDataExtractorPortlet.java:100: cannot resolve symbol
      [javac] symbol : method parseRequest (org.jboss.portlet.JBossRenderRequest)
      [javac] location: class org.apache.commons.fileupload.portlet.PortletFileUpload
      [javac] List fileItems = upload.parseRequest(request);
      [javac] ^
      [javac] 1 error
      ------------------------------------------------------------------------------------
      I have import :

      import org.apache.commons.fileupload.FileItem;
      import org.apache.commons.fileupload.disk.DiskFileItemFactory;
      import org.apache.commons.fileupload.portlet.PortletFileUpload;

      And my code is :

      DiskFileItemFactory factory = new DiskFileItemFactory();
      PortletFileUpload upload = new PortletFileUpload(factory);
      List fileItems = upload.parseRequest(request);

      , in the environment varibale, I have set the path to common-fileupload.jar
      and I use a decompiler to check the call PortletFileUpload, it has the method parseRequest(...) . But I don't why this error occur.

      *Anyone can give me a hand! Thank you!!

        • 1. Re: [HELP] File Upload Question
          ilango gurusamy Novice

          Hi
          I have the same problem too. I was told that the upload utility only works inside the CMS, but to use it inside your portlet is something alltogether a different ball-game

          I have developed my own upload portlet. I am trying to use it to modify the Image Gallery Portlet.

          I can share them code with you, so that you can try it out and help me too.

          Please get back to me. I also need to get things done

          • 2. Re: [HELP] File Upload Question
            ilango gurusamy Novice

             

            "andytsoy" wrote:
            Tools :JBoss 4.0.3sp1 + JBoss Portal 2.2

            In JBoss portal, there is a jsp to handle a user's file upload, and then it will can doView() in my portlet class.
            In my own portlet, I want to handle the upload file. But when I compile
            my .java class, there is an error as following:

            -------------------------------------------------------------------------------------
            [javac] D:\MIPS\web\nggAdminSite\portal2.2\nggDataExtractorPortlet\src\mips\nggDataExtractor\portlet\NGGDataExtractorPortlet.java:100: cannot resolve symbol
            [javac] symbol : method parseRequest (org.jboss.portlet.JBossRenderRequest)
            [javac] location: class org.apache.commons.fileupload.portlet.PortletFileUpload
            [javac] List fileItems = upload.parseRequest(request);
            [javac] ^
            [javac] 1 error
            ------------------------------------------------------------------------------------
            I have import :

            import org.apache.commons.fileupload.FileItem;
            import org.apache.commons.fileupload.disk.DiskFileItemFactory;
            import org.apache.commons.fileupload.portlet.PortletFileUpload;

            And my code is :

            DiskFileItemFactory factory = new DiskFileItemFactory();
            PortletFileUpload upload = new PortletFileUpload(factory);
            List fileItems = upload.parseRequest(request);

            , in the environment varibale, I have set the path to common-fileupload.jar
            and I use a decompiler to check the call PortletFileUpload, it has the method parseRequest(...) . But I don't why this error occur.

            *Anyone can give me a hand! Thank you!!



            My own upload code compiles easily. The only thing is, JBoss is not recognizing it. Should I drop the War into the deploy directory or is it a EAR?

            If you do not mind, could you send me your code, I can try my hand at getting it built. Reason I ask you is: I have been build my own Upload Portlet just this morning

            thanks

            • 3. Re: [HELP] File Upload Question
              Andy Andy Newbie

              I have fixed the problem.
              In JBoss Portal 2.2 . It has implement the commons-fileupload.jar.
              The only thing is to call u .
              In the jsp, Use ActionURL
              In the portlet core, it will call processAction method.
              You can take a reference of the code in JBoss portal 2.2 cms portlet.
              Thx!

              • 4. Re: [HELP] File Upload Question
                ilango gurusamy Novice

                 

                "andytsoy" wrote:
                I have fixed the problem.
                In JBoss Portal 2.2 . It has implement the commons-fileupload.jar.
                The only thing is to call u .
                In the jsp, Use ActionURL
                In the portlet core, it will call processAction method.
                You can take a reference of the code in JBoss portal 2.2 cms portlet.
                Thx!


                Should I download the lattest release for the fix?

                thanks


                • 5. Re: [HELP] File Upload Question
                  ilango gurusamy Novice

                   

                  "ilangocal" wrote:
                  "andytsoy" wrote:
                  I have fixed the problem.
                  In JBoss Portal 2.2 . It has implement the commons-fileupload.jar.
                  The only thing is to call u .
                  In the jsp, Use ActionURL
                  In the portlet core, it will call processAction method.
                  You can take a reference of the code in JBoss portal 2.2 cms portlet.
                  Thx!


                  Should I download the lattest release for the fix?

                  thanks


                  Hi
                  Could you tell me how to implement that. I am still not quite sure what to do



                  • 6. Re: [HELP] File Upload Question
                    Andy Andy Newbie

                    you can read the code for JBos portal 2.2 source code

                    \jboss-portal-2.2.0-src\core\src\main\org\jboss\portal\core\portlet\cms\admin\CMSAdminPortlet.java
                    Method processAction() for op=UPLOAD_CONTENT

                    you can also see cms in the portal interface in the IE

                    In the JSP, use actioNURL instead of renderURL

                    • 7. Re: [HELP] File Upload Question
                      ilango gurusamy Novice

                       

                      "andytsoy" wrote:
                      you can read the code for JBos portal 2.2 source code

                      \jboss-portal-2.2.0-src\core\src\main\org\jboss\portal\core\portlet\cms\admin\CMSAdminPortlet.java
                      Method processAction() for op=UPLOAD_CONTENT

                      you can also see cms in the portal interface in the IE

                      In the JSP, use actioNURL instead of renderURL



                      Hi
                      Pardon me for being naive and insistent. I am very thankful for your reply. So I should check out the source code and 'make the changes you suggested' or are you one of the core developers of the portal who has committed the changes that you mentioned to the repository?

                      I am very thankful in advance.



                      • 8. Re: [HELP] File Upload Question
                        Andy Andy Newbie

                        I am the core deveper of my portal. I have commited the changed and everything work fine.

                        For more detail.
                        In the JSP page, you should have a form like :


                        <input type=file ......>


                        In the portlet corresponding .java
                        public void processAction(JBossActionRequest aReq, JBossActionResponse aRes) throws PortletException {

                        // Prepare for processing the uploaded file
                        DiskFileItemFactory factory = new DiskFileItemFactory();
                        PortletFileUpload upload = new PortletFileUpload(factory); // TODO: configure uploader

                        // Check if the upload content is ENCTYPE="multipart/form-data" in the submitted form
                        if (upload.isMultipartContent(aReq))
                        {
                        logger.info(this.getClass().getName() + ": isMultiPart = true");

                        List fileItems = upload.parseRequest(aReq);
                        Iterator itr = fileItems.iterator();
                        while (itr.hasNext()) {
                        FileItem item = (FileItem) itr.next();

                        // check if the current item is a form field or an uploaded file
                        if (!item.isFormField()) {
                        logger.info(this.getClass().getName() + " :Start processing the uploaded file");

                        sFilename = item.getName();

                        logger.info(this.getClass().getName() + ": Filename = " + sFilename);
                        logger.info(this.getClass().getName() + ": contentType = " + item.getContentType());
                        logger.info(this.getClass().getName() + ": isInMemory = " + item.isInMemory());
                        logger.info(this.getClass().getName() + ": sizeInBytes = " + item.getSize());

                        if (item.getSize()==0){
                        logger.info(this.getClass().getName() + "No file selected ");
                        return;
                        }
                        //-- Get the inputStream of the uploaded file
                        is = item.getInputStream();

                        } else {
                        String fieldName = item.getFieldName();
                        if ("extractor_type".equals(fieldName)) {
                        extractor_type = item.getString();
                        }
                        if ("isRWKP".equals(fieldName)){
                        isRWKP = item.getString();
                        }
                        logger.info(this.getClass().getName() + ": fieldName :" + fieldName);
                        logger.info(this.getClass().getName() + ": extractor_type :" + extractor_type);
                        logger.info(this.getClass().getName() + ": isRWKP :" + isRWKP);
                        }
                        } // End while itr.hasNext()

                        logger.info(this.getClass().getName() + ": InputeStream is.length = " + is.available());
                        //* Call method extractByLOCAL
                        extractByLOCAL(extractor_type, is, sFilename, isRWKP);
                        } // End if isMultipart



                        }// End processAction()

                        The above code is what I implemented.
                        If you have any question , you can post again. In the future, I may have questions that need you for help... ^^
                        my msn is andytsoy@hotmail.com
                        you can add me