title: How to write file to server dir with Spring Framework Multipart upload files?
body: <p>I'm coding a Spring MVC project on Eclipse. I'm stuck when coding the upload picture function. The client side using HTML5 API to read and send multipart file to server. The following code was used to save the image to server.</p>
  
  <pre><code>    @RequestMapping(method = RequestMethod.POST)
  public void processUpload(@RequestParam("pic") MultipartFile file) throws IOException {
  
      // if (!result.hasErrors()) {
      FileOutputStream outputStream = null;
      String filePath = System.getProperty("java.io.tmpdir") + "/" + file.getOriginalFilename();
      try {
          outputStream = new FileOutputStream(new File(filePath));
          outputStream.write(file.getInputStream().read());
          outputStream.close();
      } catch (Exception e) {
          System.out.println("Error while saving file");
  </code></pre>
  
  <p>The file sent to server and get proceed but the file name is not original file name but some random string that java generated. I found that file in apache-tomcat-6.0.26\work\Catalina\localhost\ with name like this: upload__f20d9c4_1357767c999__7ffe_00000001. The file then disappear. 
  My question is where the file gone and how to correctly write uploaded file to some folder such as /uploads rather than save to temp folder?
  I'm new hear so please correct me if I posted wrong :D</p>