上传文件时,出现 "Could not delete file C:\Users\..." 错误
While uploading a file, getting "Could not delete file C:\Users\..." error
我正在为我的应用程序使用 spring 启动和 mysql。当我尝试上传文件时,它显示如下所示的错误消息,
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)
我的编码是,
<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>
和我的javaclass
@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.";
}
}
这似乎是 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.
我正在为我的应用程序使用 spring 启动和 mysql。当我尝试上传文件时,它显示如下所示的错误消息,
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)
我的编码是,
<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>
和我的javaclass
@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.";
}
}
这似乎是 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.