码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc MultipartFile 上传文件 当文件较小时(10k) ,无法上传成功 。

时间:2015-04-03 19:07:44      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <property name="defaultEncoding" value="UTF-8"/>  
        <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->  
        <property name="maxUploadSize" value="1024000"/>
        <property name="fileItemFactory.sizeThreshold" value="0"></property>  
    </bean>

查看该类源码 

有一段说明文档 

* <p>Provides "maxUploadSize", "maxInMemorySize" and "defaultEncoding" settings as
* bean properties (inherited from {@link CommonsFileUploadSupport}). See corresponding
* ServletFileUpload / DiskFileItemFactory properties ("sizeMax", "sizeThreshold",
* "headerEncoding") for details in terms of defaults and accepted values.

进入 CommonsFileUploadSupport 

public abstract class CommonsFileUploadSupport {

	protected final Log logger = LogFactory.getLog(getClass());

	private final DiskFileItemFactory fileItemFactory;

	private final FileUpload fileUpload;

	private boolean uploadTempDirSpecified = false;

  进入 

DiskFileItemFactory  类 
看到
/**
     * The threshold above which uploads will be stored on disk.
     */
    private int sizeThreshold = DEFAULT_SIZE_THRESHOLD;//DEFAULT_SIZE_THRESHOLD=10240就是10k

设置下这个参数即可。

spring mvc MultipartFile 上传文件 当文件较小时(10k) ,无法上传成功 。

标签:

原文地址:http://www.cnblogs.com/zhangchenglzhao/p/4390819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!