problem uploading a pdf file
jamesjmp Dec 4, 2009 7:52 AMAfter 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