The temporary upload location [/tmp/tomcat.4296537

2020-05-21 23:54发布

I am using Spring Boot 1.5.13 version.

I got the exception message like below.

Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.4296537502689403143.5000/work/Tomcat/localhost/ROOT] is not valid

I founded out this issue in Spring Github Issues. https://github.com/spring-projects/spring-boot/issues/9616

But I still have questions of that.

  1. I am not using File Upload things in my app. But the log says that "Could not parse multipart servlet request" why is that? (I got the exception when my app uses RestTemplate (Post method)
  2. To solve the exception, I rebooted my app but It did not work right away. Although i rebooted my app, it had referenced the tomcat directory which was not exist. After a day after rebooting, it worked. I guess the directory was cached in somewhere in Spring or else..?

Please Help me out!

10条回答
相关推荐>>
2楼-- · 2020-05-22 00:29

Just restart your application in the server. It is a bug between spring and tomcat servers. Once the application restarts it consume a temp directory in the server.

查看更多
Anthone
3楼-- · 2020-05-22 00:30

For me it was using the correct dependency (if using java/maven)

       <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
查看更多
贪生不怕死
4楼-- · 2020-05-22 00:32
  1. The http POST methods will use these temp locations to store the post data.
  2. Some OSs like centOS will delete the temp dir frequently. So, even you set that location's permission, after some time that dir will be removed by the OS. And after you reboot, the temp dir will be different.

You can set the multipart location in application.yml:

spring:
  http:
    multipart:
      location: /data/upload_tmp

Update

As per comment by Vivek Sethi above property didn't work for me but the below one.

spring.servlet.multipart.location=/data/upload_tmp
查看更多
男人必须洒脱
5楼-- · 2020-05-22 00:32

What I did to solve the issue was to relaunch the application adding -java.tmp.dir=/path/to/application/temp/ and creating a /temp/ folder in my application folder.

查看更多
等我变得足够好
6楼-- · 2020-05-22 00:35

You maybe encode the form body of the POST request by Content-Type: multipart/form-data http header .

You should send a Content-Type: application/x-www-form-urlencoded POST

查看更多
爷、活的狠高调
7楼-- · 2020-05-22 00:38

This Issue was fixed a couple of days ago.
Spring Boot: 2.1.4 or 1.5.20

This version bump fixes an issue when the tmp dir was deleted
by the OS and the spring boot app tries to handle a multifile
upload.

Issue: https://github.com/spring-projects/spring-boot/issues/9616

https://github.com/MeiSign/Copy-Pasta/commit/1200fb353a48a3d0c92038dee7cced7cebf3acfe

查看更多
登录 后发表回答