SpringBoot-versio:2.1.9-RELEASE

由于新版本的SpringBoot已经弃用了(1.5版本支持)如下,

这种方式,提供了新的 配置方案。

这个是官方的介绍

Handling Multipart File Uploads

Spring Boot embraces the Servlet 3 javax.servlet.http.Part API to support uploading files. By default, Spring Boot configures Spring MVC with a maximum size of 1MB per file and a maximum of 10MB of file data in a single request. You may override these values, the location to which intermediate data is stored (for example, to the /tmp directory), and the threshold past which data is flushed to disk by using the properties exposed in the MultipartProperties class. For example, if you want to specify that files be unlimited, set the spring.servlet.multipart.max-file-size property to -1.

The multipart support is helpful when you want to receive multipart encoded file data as a @RequestParam-annotated parameter of type MultipartFile in a Spring MVC controller handler method.

See the MultipartAutoConfiguration source for more details.

It is recommended to use the container’s built-in support for multipart uploads rather than introducing an additional dependency such as Apache Commons File Upload.

方案一:

  application.properties配置(yml一样,只是格式有变化)

spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=200MB

方案二:

  编写配置类,并通过@Bean标签来加入到IOC容器中管理

package cn.arebirth.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
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; @Configuration
public class FileUploadConfiuration {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件大小200mb
factory.setMaxFileSize(DataSize.ofMegabytes(200L));
//设置总上传数据大小10GB
factory.setMaxRequestSize(DataSize.ofGigabytes(10L)); return factory.createMultipartConfig();
}
}

SpringBoot 2.x版本+MultipartFile设置指定文件上传大小的更多相关文章

  1. PHP设置图片文件上传大小的具体实现方法

    PHP默认的上传限定是最大2M,想上传超过此设定的文件,需要调整PHP.apache等的一些参数 我们简要介绍一下PHP文件上传涉及到的一些参数: •file_uploads :是否允许通过HTTP上 ...

  2. 【转载】Git设置单个文件上传大小

    git单个文件默认大小是50M,超过50M,会给出warning.大于100M会无法提交: 可以通过命令,修改单个文件默认大小(以设置500M以例): git config --global http ...

  3. IIS 7 中设置文件上传大小的方法

    在IIS 6.0中设置文件上传大小的方法,就是配置如下节点: <system.web> <httpRuntime maxRequestLength="1918200&quo ...

  4. IIS 之 通过 Web.config 修改文件上传大小限制设置方法

    在IIS 6.0中,不设置默认大小为4M,设置文件上传大小的方法,maxRequestLength(KB),executionTimeout(毫秒),配置如下节点: <system.web> ...

  5. Spring boot2.0 设置文件上传大小限制

    今天把Spring boot版本升级到了2.0后,发现原来的文件上传大小限制设置不起作用了,原来的application.properties设置如下: spring.http.multipart.m ...

  6. zt对于C#中的FileUpload解决文件上传大小限制的问题设置

    对于C#中的FileUpload解决文件上传大小限制的问题设置 您可能没意识到,但对于可以使用该技术上载的文件的大小存在限制.默认情况下,使用 FileUpload 控件上载到服务器的文件最大为 4M ...

  7. struts2设置文件上传大小

    利用struts2想要设置或者限制上传文件的大小,可以在struts.xml配置文件里面进行如下配置: <constant name="struts.multipart.maxSize ...

  8. IIS 上传大文件 30MB 设置限制了上传大小

    用uploadify在IIS6下上传大文件没有问题,但是迁移到IIS7下面,上传大文件时,出现HTTP 404错误. 查了半天,原来是IIS7下的默认设置限制了上传大小.这个时候Web.Config中 ...

  9. springboot 修改文件上传大小限制

    springboot 1.5.9文件上传大小限制spring:http:multipart:maxFileSize:50MbmaxRequestSize:50Mb springboot 2.0文件上传 ...

随机推荐

  1. 如何在Linux服务器上部署Mysql

    一.安装mysql 1.通过文件上传工具,将mysql安装包上传到linux服务器上 2.卸载mariadb包,由于系统中存在mariadb包会导致mysql安装时报错mariadb-libs被mys ...

  2. 基于 Web 端 3D 地铁站可视化系统

    前言 工业互联网,物联网,可视化等名词在我们现在信息化的大背景下已经是耳熟能详,日常生活的交通,出行,吃穿等可能都可以用信息化的方式来为我们表达,在传统的可视化监控领域,一般都是基于 Web SCAD ...

  3. Celery的使用完成异步任务与定时任务

    0917自我总结 Celery的使用 一.官方文档 Celery 官网:http://www.celeryproject.org/ Celery 官方文档英文版:http://docs.celeryp ...

  4. js继承机制的实现

    js继承机制的实现 1. 继承的概念 说明继承的最经典的例子:几何形状.实际上,几何形状只有两种,即椭圆形(是圆形的)和多边形(具有一定数量的边).圆是椭圆的一种,它只有一个焦点.三角形.矩形和五边形 ...

  5. Halcon一日一练:阈值分割的几个算子

    threshold(Image:Region:MinGray:MaxGray:) 功能:得到灰度值在最小与最大这间的那些部分.其返回仍然是一个区域. MinGray<MaxGray. 这个算子可 ...

  6. xshell rz commend not found

    sudo apt-get install lrzsz 上传rz 下载sz

  7. Redis事务深入解析和使用

    作为关系型数据库中一项非常重要的基础功能--事务,在 Redis 中是如何处理并使用的? 1.前言 事务指的是提供一种将多个命令打包,一次性按顺序地执行的机制,并且保证服务器只有在执行完事务中的所有命 ...

  8. office visio 2019 下载激活

    安装 下载 office ed2k://|file|cn_office_professional_plus_2019_x86_x64_dvd_5e5be643.iso|3775004672|1E4FF ...

  9. 用Wireshark抓包分析请求

    前言 有些封装好的API把错误都屏蔽掉,直接返回某一个不明确的具体错误,让人感到困惑. //code in SDK read-only public static Data requestHandle ...

  10. Yii 数据库重连告别General error: 2006 MySQL server has gone away

    General error: 2006 MySQL server has gone away 错误原因 制造错误 解决办法 最新办法 错误原因 Mysql has gone away MySQL 服务 ...