如何在Spring Boot中同时上传多个文件?

耀华河马 5月前

我使用的是Spring Boot 1.1.3与CommonsMultipartResolver,同时上传多个文件。但是当文件超过1M时,报如下异常:

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: 
The field files[] exceeds its maximum permitted size of 1048576 bytes.
    at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:637)
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)


我试着设置更大的上传大小,如下:

public MultipartResolver multipartResolver()
{
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setMaxUploadSize( 100 * MEGABYTE_IN_BYTES );
    return resolver;
}



我能通过MultipartHttpServletRequest getFileMap()得到所有的文件,但是MultipartFile没有这样的方法。可是我希望通过MultipartFile来接收文件。

我在客户端上使用jquery-file-upload,

*
*