2016-01-08 258 views
0

我正在使用spring引導和mysql作爲我的應用程序。雖然我想上傳一個文件時,它會顯示錯誤消息像下面給出,上傳文件時,得到「無法刪除文件C: Users ...」錯誤

java.io.IOException: UT010015: Could not delete file C:\Users\KARTHI~1\AppData\Local\Temp\undertow7745669140970195692upload 
 
\t at io.undertow.servlet.spec.PartImpl.delete(PartImpl.java:111) 
 
\t at org.springframework.web.multipart.support.StandardServletMultipartResolver.cleanupMultipart(StandardServletMultipartResolver.java:86) 
 
\t at org.springframework.web.servlet.DispatcherServlet.cleanupMultipart(DispatcherServlet.java:1104) 
 
\t at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:989) 
 
\t at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) 
 
\t at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 
 
\t at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) 
 
\t at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) 
 
\t at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) 
 
\t at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
 
\t at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) 
 
\t at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) 
 
\t at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:295) 
 
\t at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
 
\t at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) 
 
\t 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 
 
\t \t \t type="text" name="name"><br /> <br /> <input type="submit" 
 
\t \t \t value="Upload"> Press here to upload the file! 
 
</form>

和我的Java類

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

+0

您是否擁有管理權限?也許就是這樣。因爲它在用戶文件夾 – Tupac

+0

@Tupac是的,我只與管理員檢查。 – Karthikeyan

回答

3

好像在暗潮(UNDERTOW-542)的錯誤在春季啓動背景下討論here。引用analysis of Andy Wilkinson

好消息是,例外的良性,你可以放心地忽略它。它只是告訴你,儘管非常吵鬧,因爲它已被刪除,所以文件不能被刪除。原因是Undertow中存在競爭條件,這意味着兩個線程最終同時嘗試刪除文件。

[...]

這已被固定在暗流1.3和1.2。 Spring Boot 1.3使用Undertow 1.3,所以我們在那裏很好。不幸的是,Spring Boot 1.2使用了Undertow 1.1,所以我們只能忍受那裏的良性警告。