SpringBoot 錯誤:The temporary upload location is valid

這個是文件上傳時臨時路徑找不到了,爲了萬無一失可以在配置中指定臨時文件存儲的路徑

package jp.co.bbj.web.common.utils;

import javax.servlet.MultipartConfigElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author CCT
 */
@Configuration
public class FileUploadConfig {

    @Autowired
    private CommonConfig config;

    @Bean
    public MultipartConfigElement multipartConfigElement(
            @Value("${multipart.maxFileSize}") String maxFileSize,
            @Value("${multipart.maxRequestSize}") String maxRequestSize) {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 指定上傳文件的大小
        factory.setMaxFileSize(maxFileSize);
        // 多文件上傳總大小
        factory.setMaxRequestSize(maxRequestSize);
        // 指定臨時文件存儲路徑
        factory.setLocation(config.getTempFilePath());
        return factory.createMultipartConfig();
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章