title: How to customize file upload directory in Spring Boot
body: <p>I am using Spring Boot to upload files. Currently, all the uploaded files are stored in a "upload dir" directory. Like this:</p>
  
  <pre><code>public static String ROOT = "upload-dir";
  </code></pre>
  
  <p>The upload method looks like this (ROOT is where the file will be stored):</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/")
  public String handleFileUpload(@RequestParam("file") MultipartFile file,
                                 RedirectAttributes redirectAttributes) {
  
      if (!file.isEmpty()) { 
          try { 
              // Java NIO to copy the input stream to a local file
              Files.copy(file.getInputStream(), Paths.get(ROOT, file.getOriginalFilename()));
              redirectAttributes.addFlashAttribute("message",
                      "You successfully uploaded " + file.getOriginalFilename() + "!");
          } catch (IOException|RuntimeException e) {
              redirectAttributes.addFlashAttribute("message", "Failued to upload " + file.getOriginalFilename() + " =&gt; " + e.getMessage());
          }
      } else {
          redirectAttributes.addFlashAttribute("message", "Failed to upload " + file.getOriginalFilename() + " because it was empty");
      }
  
      return "redirect:/";
  }
  </code></pre>
  
  <p>How do I change ROOT so that it asks the user for a specific a temporary location instead of loading up the file system of the application? </p>