开发者

HTTP error when uploading .pdf, .doc or .docx. files with primefaces upload tool

I am using the Primefaces upload tool since yesterday, but today i started to test it with different file extensions. My surprise was that the only file that i can succesfully upload is .txt I dont understand why is that. I saw code snipets around the web and i think my code is almost the same. Am i missing something?

Here a bit more info:

This is the error:

HTTP error when uploading .pdf, .doc or .docx. files with primefaces upload tool

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception java.io.IOException: Processing of multipart/form-data request failed. \uploaded\upload_3be1503c_12f00f7e117__7ffb_00000007.tmp (The system cannot find the path specified) at org.primefaces.webapp.MultipartRequest.parseRequest(MultipartRequest.java:67) at org.primefaces.webapp.MultipartRequest.(MultipartRequest.java:49)

This is the code at the JSF

<h:form enctype="multipart/form-data">

  <!-- New Upload tool -->
        <p:fileUpload fileUploadListener="#{uploadController.handleFileUpload}"   
        allowTypes="*.doc;*.docx;*.pdf;*.odt;" description="Text"/>

</h:form>

This is part of the code at the managed bean

            public void handleFileUpl开发者_如何学Pythonoad(FileUploadEvent event) {

    uploadedFile = event.getFile();
    String fileName = FilenameUtils.getName(uploadedFile.getFileName());
    String contentType = uploadedFile.getContentType();
    byte[] bytes = uploadedFile.getContents();

    Garbage garbage = new Garbage();
    garbage.setFilename(fileName);
    garbage.setFile(bytes);
    garbage.setDescription("info about the file");
    garbage.setFileType("File extension");
    fileUploaderEJB.uploadGarbage(garbage);

    FacesContext.getCurrentInstance().addMessage(
            null,
            new FacesMessage(String.format(
                    "File '%s' of type '%s' successfully uploaded!",
                    fileName, contentType)));
}

Just in case, the primefaces related sutuff at web.xml

<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping> 
 <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter
    </filter-class>
    <init-param>
        <param-name>uploadDirectory</param-name>
        <param-value>/uploaded</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>


\uploaded\upload_3be1503c_12f00f7e117__7ffb_00000007.tmp (The system cannot find the path specified)

The folder /uploaded on the same root disk as where your webserver is installed is missing. Create it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜