Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect content type for PDF file with Firefox
    primarykey
    data
    text
    <p>I am using Spring 3.2.0.M2 and I am trying to upload a pdf file.</p> <p>JSP file :</p> <pre><code>&lt;form method="POST" action="upload" enctype="multipart/form-data&gt; &lt;input type="file" name="file" /&gt; &lt;/form&gt; </code></pre> <p>Controller :</p> <pre><code>@RequestMapping(value = "/upload", method = RequestMethod.POST) public String handleUpload(@RequestParam MultipartFile file) { System.out.println(file.getContentType()); //prints "application/text-plain:formatted" } </code></pre> <p>I am using the Standard multipart resolver :</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;multipart-config /&gt; &lt;/servlet&gt; </code></pre> <p>with :</p> <pre><code>&lt;bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"&gt; &lt;/bean&gt; </code></pre> <p>I also tried with CommonsMultipartResolver from Apache but the problem is the same.</p> <p>What I am getting is "application/text-plain:formatted" instead of "application/pdf". I tested with several pdf file (from different sources). When I try to upload another file type (e.g. Word document), it works as expected (for a Word document, I get "application/msword").</p> <p>I intend to store the content type (and the file name) into a database for later retrieval and download of the file. Having an incorrect content type is then causing an exception when calling setContentType like this :</p> <pre><code>public void downloadResource(@RequestParam("resId") Long resourceId, HttpServletResponse response) { // get resource with its id. response.setContentType(resource.getContentType()); //throws org.apache.tomcat.util.http.parser.TokenMgrError } </code></pre> <p>The exception message is :</p> <blockquote> <p>Lexical error at line 1, column 23. Encountered: ":" (58), after : ""</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload