现在客户端是安卓的,在安卓客户端拍照提交照片上传请求的时候,由于无法获知客户端的file名称所以无法使用spring mvc的@RequestParam("file") MultipartFile file,然后考虑使用request,通过DiskFileItemFactory和ServletFileUpload做文件上传,但当获取FileItem时,获取到的内容为空,无法获取到上传文件。不知道是怎么回事,请各位大牛解释一下。
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024 * 1024);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setFileSizeMax(1024 * 1024 * 2);
upload.setHeaderEncoding("utf-8");
upload.setSizeMax(1024 * 1024 * 4);
List<FileItem> fileList = null;
try {
//此处断点后fileList为空
fileList = upload.parseRequest(new ServletRequestContext(request));
if(fileList != null){
for(FileItem item:fileList){
if(!item.isFormField() && item.getSize() > 0){
item.write(new File(path));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}