The file upload failed because the temporary directory was deleted. The simple and crude solution is to restart the project and regenerate the temporary directory. The disadvantage is that the temporary directory will be cleared after a period of time.
The solution is to modify the application.yml configuration file and add the configuration of the temporary directory as follows:
spring:
servlet:
# 上传限定参数
multipart:
# 是否启用分段上传支持
enabled: true
# 最大请求大小
max-request-size: 1000MB
# 最大文件的大小
max-file-size: 5000MB
#上传文件的中间位置
location: /home/app/temp
Then add a configuration under the startup class to automatically create the directory
@Configuration
@SpringBootApplication
@ServletComponentScan
public class Application {
@Value("${spring.servlet.multipart.location}")
private String tempDir;
@Bean
public void mkDir(){
File file = new File(tempDir);
if (file.exists()){
System.out.println("文件夹存在");
}else {
System.out.println("文件夹不存在");
file.mkdirs(); //创建文件夹
}
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}