简体   繁体   中英

While uploading a file, getting “Could not delete file C:\Users\…” error

I am using spring boot and mysql for my application. While I am trying to upload a file it shows error message like given below,

 java.io.IOException: UT010015: Could not delete file C:\\Users\\KARTHI~1\\AppData\\Local\\Temp\\undertow7745669140970195692upload at io.undertow.servlet.spec.PartImpl.delete(PartImpl.java:111) at org.springframework.web.multipart.support.StandardServletMultipartResolver.cleanupMultipart(StandardServletMultipartResolver.java:86) at org.springframework.web.servlet.DispatcherServlet.cleanupMultipart(DispatcherServlet.java:1104) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:989) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:295) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) 

and my coding is,

 <form method="POST" enctype="multipart/form-data" action="http://localhost:8080/surf/upload"> File to upload: <input type="file" name="file"><br /> Name: <input type="text" name="name"><br /> <br /> <input type="submit" value="Upload"> Press here to upload the file! </form> 

and my java class

  @RequestMapping(value="/upload", method=RequestMethod.POST) public @ResponseBody String handleFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file){ if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File("D:/Test/surfImg/"))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + "!"; } catch (Exception e) { return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } } 

It seems like a bug in Undertow ( UNDERTOW-542 ) discussed here in Spring Boot context. To quote the analysis of Andy Wilkinson :

The good news is that the exception's benign and you can safely ignore it. All it's telling you, albeit very noisily, is that the file couldn't be deleted as it's already been deleted. The reason is that there's a race condition in Undertow that means that two threads end up trying to delete the file at the same time.

[...]

This has been fixed in Undertow 1.3 and 1.2. Spring Boot 1.3 uses Undertow 1.3 so we're good there. Unfortunately Spring Boot 1.2 uses Undertow 1.1 so we'll just have to live with the benign warning there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM