从1.3.8升级到Spring Boot 1.5.2后,我们的流式文件上传不再有效。
这是设置。
multipart.enabled:false
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
...
@RequestMapping(
value = '/upload ,
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<MyObject> uploadFile(HttpServletRequest request) {
ResponseEntity<MyObject> retval = null;
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request); <<<
// iter contains no elements when using SpringBoot 1.5.2
// iter does contain the expected elements when using SpingBoot 1.4.+
// I tried commons-fileupload:1.3.1 and 1.3.3
while (iter.hasNext()) { <<< no elements when using Spring boot 1.5
...
}
...
}
答案 0 :(得分:1)
在Spring Boot 1.4版中,多部分命名空间已更改为spring.http.multipart。要禁用Spring Boot StandardServletMultipartResolver,它还会禁用写入磁盘的嵌入式tomcat文件上载,而是需要设置新的环境属性。
我在application.yml
中这样做spring.http.multipart.enabled:false
这允许将没有写入磁盘的commons-fileupload流在我的环境中再次工作。