The system on the line cannot upload the file, the following error occurred:
not parse multipart servlet request;nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1337767218595042057.80/work/Tomcat/localhost/ROOT] is not valid org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:112) org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.
Reason:
In the linux
system, springboot
when the application service is restarted (the java -jar
command starts the service), /tmp
a file directory is generated under the operating system directory tomcat*
, and the uploaded files are converted to temporary files to be saved under this folder. Because /tmp
files in the temp directory are not used for a long time (10 days), they are automatically deleted by the system mechanism. So if the system is neglected for a long time, it can lead to the above problem.
Workaround:
@Bean
public Multipartconfigelement multipartconfigelement () {
Multipartconfigfactory factory = new Multipartconfigfactory ();
factory.setlocation ("/data/app/temp");
//file Max
Factory.setmaxfilesize ("10240KB"); KB,MB
///Set total upload data total size
factory.setmaxrequestsize (" 102400KB ");
return Factory.createmultipartconfig ();
}
Manually setting the Temp folder to a custom folder will not be deleted by Linux.
PS: windows系统
This path will be generated automatically in the system, /data/apps/temp
but the Linux系统
path will not be generated /data/apps/temp
in
Springboot temporary invalidation of uploaded files