[SpringBoot2.4.3] uploadを任意の場所にファイルを保存

Controller.java
L new FileOutputStream(${path})で、保存場所を指定する

	@RequestMapping(value="upload", method=RequestMethod.POST)
    public void handle(
            HttpServletResponse response,
            @RequestParam MultipartFile file
            ) {
        if(file.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        try {
            BufferedInputStream in = new BufferedInputStream(file.getInputStream());
            BufferedOutputStream out = new BufferedOutputStream(
                    new FileOutputStream("./target/" + file.getOriginalFilename()));
        } catch (IOException e) {
            throw new RuntimeException("Error uploading file.", e);
        }
    }

なるほど、resourcesのstaticの中に置くこともできますね。

new FileOutputStream(“./src/main/resources/static/file/” + file.getOriginalFilename())

### filenameをreturn
res.getWriter().write(file.getOriginalFilename());

OK、後は基本機能としてはログインのみなんだよなー