title: HTTP status 500 when using file upload with freemarker
body: <p>I'm trying to add an image upload in my freemarker page(ftl file) using spring and hibernate technology -
  this is the error I had every time I run the application :</p>
  
  <blockquote>
    <p>HTTP Status 500 - The server
    encountered an internal error () that
    prevented it from fulfilling this
    request.</p>
  </blockquote>
  
  <p>and this is the code:</p>
  
  <p>1-POM file :</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
      &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
      &lt;version&gt;1.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
      &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
      &lt;version&gt;1.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>2-app-config.xml :</p>
  
  <pre><code>&lt;bean id="multipartResolver"
  class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/&gt;
  </code></pre>
  
  <p>3-ftl file :</p>
  
  <pre><code>&lt;input type="file" id="image" name="image" value=""&gt;
  </code></pre>
  
  <p>4-web controller :</p>
  
  <pre><code>@RequestMapping(method= RequestMethod.POST)
  public String post(Model model , HttpServletRequest req , HttpSession session,@RequestParam("image") MultipartFile multipartFile) throws IOException{
  
      // transfer the uploaded image to the place where images exist in project 
      multipartFile.getBytes();
      File destination = new File("/home/user/Pictures/" + multipartFile.getOriginalFilename());
      multipartFile.transferTo(destination);
  
  
      // delete the original uploaded image
      destination.delete();
  
  
      return "redirect:index";
  
  }
  </code></pre>