2016-07-03 7 views
0

私はSpringブートを使用してファイルをアップロードしています。現在、アップロードされたすべてのファイルは "upload dir"ディレクトリに保存されています。このように:Springブートでファイルアップロードディレクトリをカスタマイズする方法

それは固有の一時をユーザーに要求するように、私はルートを変更するにはどうすればよい
@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() + " => " + e.getMessage()); 
     } 
    } else { 
     redirectAttributes.addFlashAttribute("message", "Failed to upload " + file.getOriginalFilename() + " because it was empty"); 
    } 

    return "redirect:/"; 
} 

public static String ROOT = "upload-dir"; 

アップロード方法は、この(ファイルを保存する場所をROOTがある)のように見えますアプリケーションのファイルシステムをロードする代わりに、場所を指定しますか?

+0

、私は完全にあなたの質問を取得していないが、あなたは、アップロードされたファイル*の*中級場所を変更したい場合'application.properties'に' multipart.location'をセットします –

答えて

0

変更ROOT uがしたい任意のパスに、LIKE「C:/ myphoto」

関連する問題