6 Replies Latest reply on Nov 11, 2011 10:58 AM by cdelosrios

    problem uploading a pdf file

      After uploading without any problem xml files now I´m trying to upload a pdf file from a form with rich:rich:fileUpload and what seemed to be a piece of cake has become a nightmare.
      To start with this is my web.xml config:

       <filter>
       <filter-name>Seam Filter</filter-name>
       <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
       <init-param>
       <param-name>maxRequestSize</param-name>
       <param-value>104860000</param-value>
       </init-param>
       </filter>
      
       <filter-mapping>
       <filter-name>Seam Filter</filter-name>
       <url-pattern>/*</url-pattern>
       </filter-mapping>
      
      
      <filter>
      <filter-name>Seam Multipart Filter</filter-name>
       <filter-class>org.jboss.seam.web.MultipartFilter2</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>Seam Multipart Filter</filter-name>
       <url-pattern>*.seam</url-pattern>
      </filter-mapping>
      


      and this is my components.xml:
       <web:multipart-filter create-temp-files="true"
       max-request-size="104860000"
       url-pattern="*.seam"/>
      
      


      In the form I have several fields, one of them is to upload a pdf or xml file.

       <h:form id="apoderado" styleClass="edit" enctype="multipart/form-data">
      ...
       <s:decorate id="asdf" template="layout/edit.xhtml">
       <div align="center">
       <ui:define name="label">Fichero firma (pdf)</ui:define>
       <rich:fileUpload id="upload"
       fileUploadListener="#{ApoderadoEdit.fileUploadListener}"
       acceptedTypes="pdf,xml"
       maxFilesQuantity="1">
       <f:facet name="label">
       <h:outputText value="{_KB}KB de {KB}KB cargados --- {mm}:{ss}" />
       </f:facet>
       </rich:fileUpload>
       <img src="Captcha.jpg"/>
      </div>
      
      </s:decorate>
      ...
      


      And this is the listener:
      public void fileUploadListener(org.richfaces.event.UploadEvent event)
      {
       try{
       if(event==null){
       log.debug("null upload event");
       return;
       }
       UploadItem item = event.getUploadItem();
       String name = "unnamed_attachment";
       byte[] data = item.getData();
       generadorDirectorio();
       if (item.isFile()) {
       data = item.getData();
       File file = item.getFile();
       name = FilenameUtils.getName(item.getFileName());
       String fileName=Util.PATH+name;
       File outputFile = new java.io.File(fileName);
       FileReader in = new FileReader(file);
       FileWriter out = new FileWriter(outputFile);
       int c;
       while ((c = in.read()) != -1)
       out.write(c);
      
       in.close();
       out.close();
       }
       }catch (Exception e) {
       e.printStackTrace();
       }
      }
      
      


      With xml files it works, but when I upload a pdf it saves a pdf with different size (bigger) and when I try to open it it asks for a Document open password. I have not configured anything relate to pdf file protection anywhere. In fact Original pdf selected to be uploaded has no protection at all.
      thanks in advance,
      Jaime

        • 1. Re: problem uploading a pdf file

          By the way, I´ve checked that with other pdf files I´m not ask for a document password but pdf displayed have only blank pages.

          • 2. Re: problem uploading a pdf file
            ilya_shaikovsky

             

            With xml files it works, but when I upload a pdf it saves a pdf with different size (bigger) and when I try to open it it asks for a Document open password. I have not configured anything relate to pdf file protection anywhere. In fact Original pdf selected to be uploaded has no protection at all.


            I can't imaging how that could be caused by upload :)

            And b.t.w. you not need in separate multipart filter definition for RichFaces upload component.

            • 3. Re: problem uploading a pdf file

              Thanks, I added it just in case, but to no avail. Adding or removing that means no change, pdf data is not uploaded. I have removed it to have configuration cleaner.

              • 4. Re: problem uploading a pdf file
                nbelaevski

                Hi,

                1. You are using very inefficient method of copying file contents. Use NIO or at least add buffering for data.
                2. Reader/Writer are used for character streams, but .PDF is definitely not a characters, but bytes. I think this is the cause for some valueable bits to break.

                • 5. Re: problem uploading a pdf file

                  you´re right, it all was just a problem of the way I was saving the pdf file.
                  With NIO I´ve solved it. thank you very much!

                  • 6. Re: problem uploading a pdf file
                    cdelosrios

                    please, could you post your solution....I'm trying to upload pdf files and have the same problem.

                     

                    Thanks in advance.