springboot設置文件上傳限制


參考springboot最大上傳文件配置

package com.ustcinfo.fn.config;

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;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * @author Jamin
 * @date 2020/11/12 17:54
 */
@Configuration
public class TomcatConfig {
	@Value("${spring.server.MaxFileSize}")
	private String maxFileSize;
	@Value("${spring.server.MaxRequestSize}")
	private String maxRequestSize;

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//  單個數據大小
		factory.setMaxFileSize(DataSize.parse(maxFileSize));
		/// 總上傳數據大小
	 factory.setMaxRequestSize(DataSize.parse(maxRequestSize));
		return factory.createMultipartConfig();
	}
}
#文件上傳限制默認10m
# 無用spring.servlet.multipart.max-file-size
spring.server.MaxFileSize=104857600
spring.server.MaxRequestSize=104857600


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM