我正在为我的应用程序使用spring boot和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>
&#13;
和我的java类
@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.";
}
}
&#13;
答案 0 :(得分:2)
似乎是Undertow(UNDERTOW-542)中的一个错误在Spring Boot上下文中讨论了here。引用analysis of Andy Wilkinson:
好消息是异常是良性的,你可以放心地忽略它。所有它告诉你,虽然非常吵闹,但是文件无法删除,因为它已被删除。原因是Undertow中存在竞争条件,这意味着两个线程最终会同时尝试删除该文件。
[...]
这已在Undertow 1.3和1.2中修复。 Spring Boot 1.3使用Undertow 1.3,所以我们在那里很好。不幸的是,Spring Boot 1.2使用了Undertow 1.1,因此我们只需要接受良性警告。