无法将文件保存在控制器的磁盘上

时间:2017-12-11 09:00:29

标签: java file spring-mvc spring-boot multipartform-data

我有以下控制器:

@PostMapping(value = "/load_attachment")
    public DeferredResult uploadingPost(@RequestParam("attachment") MultipartFile[] uploadingFiles, @RequestParam("stoneId") String stoneId) throws IOException {
        logger.info("Upload {} files for stone: {}", uploadingFiles.length, stoneId);
        for (MultipartFile uploadedFile : uploadingFiles) {
            File file = new File(uploadedFile.getOriginalFilename());
            uploadedFile .transferTo(file);
            logger.info("path:{}", file.getAbsolutePath()); // I expect to find files here

        }
}

没有异常发生,但我无法在文件系统上找到文件。

1 个答案:

答案 0 :(得分:0)

在您的情况下,应用程序服务器不在文件夹路径中的应用程序服务器,因此您应手动指定它!...

Environment.getProperty("myCollection", Set.class)

供进一步参考https://www.programcreek.com/java-api-examples/index.php?class=org.springframework.web.multipart.MultipartFile&method=transferTo