简体   繁体   English

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

[英]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"+uploadedFil‌e.getOriginalFilenam‌e());
        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.

相关问题 如何在 android 中安全地将文件保存到磁盘? - How to safely save a file to disk in android? Android:如何将临时文件保存到磁盘? - Android: how to save temporary file to disk? 如何解析http标头以获取上传文件并将其保存到磁盘 - How to parse http header to get uploaded file and save it to disk 尝试将附加的味精文件保存在Java的本地磁盘中 - Trying to save attached msg file in local disk in java Servlet-将文件保存到磁盘,但不确定使用什么路径? - Servlet - save file to disk, but not sure what path to use? 将目录从jar文件保存到用户磁盘 - Save a directory from a jar file to the user's disk 如何将CSV文件加载到Apache箭头向量并将箭头文件保存到磁盘 - How to load a CSV file into Apache Arrow vectors and save an arrow file to disk 如何保存从 HTTP 获取的文件在磁盘文件 java 上获取响应 - How to save file getting from HTTP GET response on disk file java 可能是 java 中的外部文件路径? 我的意思是不存储在电脑硬盘中,而是存储在其他地方(例如:云,...) - Could be file_path external in java? I mean not storing in pc hard disk, but somewhere else (ex: cloud, …) 编写BufferedImage缓存并将其保存到磁盘 - Writing a BufferedImage cache and save it to disk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM