[英]Could not save file on disk in controller
I have following controller: 我有以下控制器:
@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
}
}
No exceptions happens but I could not find files on file system. 没有例外发生,但我无法在文件系统上找到文件。
In your case, Application server doesn't application server inside folder path so you should specify it manually!... 在您的情况下,应用程序服务器不在文件夹路径内,因此您应该手动指定它!
for (MultipartFile uploadedFile : uploadingFiles) {
File file = new File("path/to/your/server/application/directory"+uploadedFile.getOriginalFilename());
uploadedFile .transferTo(file);
logger.info("path:{}", file.getAbsolutePath()); // I expect to find files here
}
for further reference https://www.programcreek.com/java-api-examples/index.php?class=org.springframework.web.multipart.MultipartFile&method=transferTo 以获得更多参考https://www.programcreek.com/java-api-examples/index.php?class=org.springframework.web.multipart.MultipartFile&method=transferTo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.