728x90
반응형

대략 아래와 같은 에러가 났습니다.

java.io.IOException: java.io.FileNotFoundException: C:\Users\WINDOWS_ACCOUNT\AppData\Local\Temp\tomcat.8091.3989423076524435769\work\Tomcat\localhost\ROOT\upload_f1f22731_c8ce_4036_a01a_d6ef88fcee54_00000030.tmp (지정된 파일을 찾을 수 없습니다)

 

기존에 잘 사용하던 코드였는데 갑자기 나더군요.

문제는 C:\Users\WINDOWS_ACCOUNT는 제가 업로드 하려던 폴더가 아닙니다.

multipartfile.transferto(file)를 사용 시 나는 것으로, 절대경로를 사용하지 않으면 문제가 되는 겁니다.

 

* 참고정보

 

Spring MVC Multipart file upload random FileNotFoundException

I built a web application using spring MVC, everything is working fine except the file upload in which I got random FileNotFoundExceptions. I found some solutions online like using a different tmp ...

stackoverflow.com

 

그래서 해당 부분에 절대 경로를 사용하도록 수정하여 문제를 해결 했습니다.

아래는 필수 내용만 남긴 셈플 소스 입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
final String uploadPath = "C:\\upload/";
Iterator<String> itr = request.getFileNames();
long currentTime = System.currentTimeMillis();
 
try {
    
    while (itr.hasNext()) {
        
        // extract file
        String fileName = itr.next();
        MultipartFile serverFile = request.getFile(fileName);
        String requestName = serverFile.getName();
        
        // 파일 유무 확인
        if (serverFile.isEmpty()) {
            // 업로드 파일 없음 프로세스    
        } else {
            // 신규 업로드 파일
            String systemName = String.format("%s.%s"String.valueOf(currentTime++), "jpg");
            String fullFilePath = uploadPath + File.separator + systemName;
            // 업로드된 자바의 파일 객체
            // File toFile = new File(fullFilePath);
            // serverFile.transferTo(toFile);
            Path path = Paths.get(fullFilePath).toAbsolutePath();
            serverFile.transferTo(path.toFile());
        }
    }
 
catch (Exception e) {
    logger.error("temporary file upload failed", e);
cs

위 소스 중 주석처리한 22, 23번 라인은 기존에 사용하던 소스로 23번에서 에러가 납니다.

이를 24, 25번 라인과 같이 수정하면 정상 절대경로를 사용하게 되어 작동합니다.

 

* 에러 전문

java.io.IOException: java.io.FileNotFoundException: C:\Users\WINDOWS_ACCOUNT\AppData\Local\Temp\tomcat.8091.3989423076524435769\work\Tomcat\localhost\ROOT\upload_f1f22731_c8ce_4036_a01a_d6ef88fcee54_00000030.tmp (지정된 파일을 찾을 수 없습니다)

at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:122)

at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:256)

at packageName.core.common.utils.FileUploadUtil.uploadProcess(FileUploadUtil.java:121)

at packageName.admin.research.service.ResearchService.updateQustList(ResearchService.java:404)

at packageName.admin.research.service.ResearchService$$FastClassBySpringCGLIB$$3dac1fd9.invoke()

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)

at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)

at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)

at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)

at packageName.admin.research.service.ResearchService$$EnhancerBySpringCGLIB$$b7649e19.updateQustList()

at packageName.admin.research.web.ResearchController.updateQustList(ResearchController.java:178)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197)

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:880)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)

at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)

at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:887)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)

Caused by: java.io.FileNotFoundException: C:\Users\WINDOWS_ACCOUNT\AppData\Local\Temp\tomcat.8091.3989423076524435769\work\Tomcat\localhost\ROOT\upload_f1f22731_c8ce_4036_a01a_d6ef88fcee54_00000030.tmp (지정된 파일을 찾을 수 없습니다)

at java.io.FileInputStream.open0(Native Method)

at java.io.FileInputStream.open(Unknown Source)

at java.io.FileInputStream.(Unknown Source)

at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:404)

at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:120)

... 64 more

- userMessage: null

- systemMessage: java.io.FileNotFoundException: C:\Users\WINDOWS_ACCOUNT\AppData\Local\Temp\tomcat.8091.3989423076524435769\work\Tomcat\localhost\ROOT\upload_f1f22731_c8ce_4036_a01a_d6ef88fcee54_00000030.tmp (지정된 파일을 찾을 수 없습니다)

- httpStatus: 500 INTERNAL_SERVER_ERROR

- code: null

 

 

 

728x90
반응형

+ Recent posts