
I am sending to controller multipartfile and when logic in controller is completed spring invokes error:
2015-09-10 10:41:05 WARN (StandardServletMultipartResolver.java:91) - Failed to perform cleanup of multipart items java.io.IOException: UT010015: Could not delete file ....\Path\undertow6870903013120486522upload at io.undertow.servlet.spec.PartImpl.delete(PartImpl.java:111)
My controller:
@RequestMapping(value = "api/{name}/file", method = RequestMethod.POST,consumes="multipart/form-data") public ResponseEntity<?> receiveFile(@RequestParam(value = "file") MultipartFile multipartFile, @PathVariable("name") String name) throws IOException { logic here return new ResponseEntity<>(HttpStatus.OK); }
I am using AngularJS (ng-file-upload module) to send file:
file.upload = Upload.upload({ url: sUrl, method: 'POST', headers: {'Content-Type': '"multipart/form-data'}, file: file, fileFormDataName: 'file' });
3 Answers
Are you using Tomcat or Undertow as your application server?
If it's Undertow, it may just be a benign exception informing you that the temporary file can't be deleted because it's already been deleted (source: https://github.com/spring-projects/spring-boot/issues/3966 which also mentions a bug ticket open UNDERTOW-542 ).
I ran into this same issue when running a jHipster-based project using the fast
profile, which uses Undertow. Everything worked as expected, but this error was thrown. If I used the dev
profile, which uses Tomcat, no error was thrown.
I ran into the same issue when I started using Spring 4.3.1.RELEASE
with wildfly 9.x
.
To fix the issue I just updated my Spring version from 4.2.2.RELEASE
to 4.2.3.RELEASE
which solved the issue.
This is my service class
@Override public String uploadImage(String path, MultipartFile file) throws IOException { // File Name String name = file.getOriginalFilename(); //Random name generate of file String randomID=UUID.randomUUID().toString(); String fileName1= randomID.concat(name.substring(name.lastIndexOf("."))); // Full Path String filePath = path + File.separator + fileName1; // Create folder if not create File f = new File(path); if (!f.exists()) { f.mkdir(); } // file copy Files.copy(file.getInputStream(), Paths.get(filePath)); //System.gc(); //or f.delete(); /* I am resolve my exception using above System.gc(); or f.delete() method using both are working for me */ return fileName1; }
1ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoamtsaWyDdoOOrKeroZ6ceqq%2FjK6lmpqcmnq1u4ypnKuen6e6bq%2FLnpinraBivKd5zK6jraGglr%2B1ecitnKar