Springboot temporary invalidation of uploaded files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.