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 }
您是否擁有管理權限?也許就是這樣。因爲它在用戶文件夾 – Tupac
@Tupac是的,我只與管理員檢查。 – Karthikeyan