Java Code Examples for org.springframework.web.multipart.MultipartHttpServletRequest#getFiles()
The following examples show how to use
org.springframework.web.multipart.MultipartHttpServletRequest#getFiles() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestParamMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class); Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest); if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) { return mpArg; } Object arg = null; if (multipartRequest != null) { List<MultipartFile> files = multipartRequest.getFiles(name); if (!files.isEmpty()) { arg = (files.size() == 1 ? files.get(0) : files); } } if (arg == null) { String[] paramValues = request.getParameterValues(name); if (paramValues != null) { arg = (paramValues.length == 1 ? paramValues[0] : paramValues); } } return arg; }
Example 2
Source File: OSS.java From wangmarket with Apache License 2.0 | 6 votes |
/** * SpringMVC 上传图片文件,配置允许上传的文件后缀再 systemConfig.xml 的OSS节点 * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/" * @param request SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存 * @param formFileName form表单上传的单个图片文件,表单里上传文件的文件名 * @param maxWidth 上传图片的最大宽度,若超过这个宽度,会对图片进行等比缩放为当前宽度。 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功 */ public static UploadFileVO uploadImage(String filePath,HttpServletRequest request,String formFileName, int maxWidth) { UploadFileVO uploadFileVO = new UploadFileVO(); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles(formFileName); if(imageList.size()>0 && !imageList.get(0).isEmpty()){ MultipartFile multi = imageList.get(0); uploadFileVO = uploadImageByMultipartFile(filePath, multi, maxWidth); }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } return uploadFileVO; }
Example 3
Source File: OSS.java From wangmarket with Apache License 2.0 | 6 votes |
/** * SpringMVC 上传单个图片文件,配置允许上传的文件后缀再 systemConfig.xml 的OSS节点 * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/" * @param request SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存 * @param formFileName form表单上传的单个图片文件,表单里上传文件的文件名 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功 */ public static UploadFileVO uploadImageByRequest(String filePath, HttpServletRequest request, String formFileName) { UploadFileVO uploadFileVO = new UploadFileVO(); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles(formFileName); if(imageList.size()>0 && !imageList.get(0).isEmpty()){ uploadFileVO = uploadImageByMultipartFile(filePath, imageList.get(0)); }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } return uploadFileVO; }
Example 4
Source File: OSS.java From wangmarket with Apache License 2.0 | 6 votes |
/** * SpringMVC 上传单个图片文件,配置允许上传的文件后缀再 systemConfig.xml 的OSS节点 * <br/> 建议使用 uploadImageByRequest * @param filePath 上传后的文件所在OSS的目录、路径,如 "jar/file/" * @param request SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存 * @param formFileName form表单上传的单个图片文件,表单里上传文件的文件名 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功 * @deprecated */ public static UploadFileVO uploadImage(String filePath, HttpServletRequest request, String formFileName) { UploadFileVO uploadFileVO = new UploadFileVO(); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles(formFileName); if(imageList.size()>0 && !imageList.get(0).isEmpty()){ uploadFileVO = uploadImageByMultipartFile(filePath, imageList.get(0)); }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } return uploadFileVO; }
Example 5
Source File: AttachmentFile.java From wangmarket with Apache License 2.0 | 6 votes |
/** * SpringMVC 上传图片文件,配置允许上传的文件后缀再 systemConfig.xml 的AttachmentFile节点 * @param filePath 上传后的文件所在的目录、路径,如 "jar/file/" * @param request SpringMVC接收的 {@link MultipartFile},若是有上传图片文件,会自动转化为{@link MultipartFile}保存 * @param formFileName form表单上传的单个图片文件,表单里上传文件的文件名 * @param maxWidth 上传图片的最大宽度,若超过这个宽度,会对图片进行等比缩放为当前宽度。 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功 */ public static UploadFileVO uploadImage(String filePath,HttpServletRequest request,String formFileName, int maxWidth) { UploadFileVO uploadFileVO = new UploadFileVO(); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles(formFileName); if(imageList.size()>0 && !imageList.get(0).isEmpty()){ MultipartFile multi = imageList.get(0); uploadFileVO = uploadImageByMultipartFile(filePath, multi, maxWidth); }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } return uploadFileVO; }
Example 6
Source File: AttachmentFile.java From wangmarket with Apache License 2.0 | 6 votes |
/** * SpringMVC 上传文件,配置允许上传的文件后缀再 systemConfig.xml 的AttachmentFile节点 * @param filePath 上传后的文件所在的目录、路径,如 "jar/file/" * @param request SpringMVC接收的 {@link MultipartFile},若是有上传文件,会自动转化为{@link MultipartFile}保存 * @param formFileName form表单上传的单个文件,表单里上传文件的文件名 * @return {@link UploadFileVO} 若成功,则上传了文件并且上传成功 */ public static UploadFileVO uploadFile(String filePath,HttpServletRequest request,String formFileName) { UploadFileVO uploadFileVO = new UploadFileVO(); if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> list = multipartRequest.getFiles(formFileName); if(list.size()>0 && !list.get(0).isEmpty()){ MultipartFile multi = list.get(0); uploadFileVO = uploadFileByMultipartFile(filePath, multi); }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } return uploadFileVO; }
Example 7
Source File: OptAttachmentServiceImpl.java From paascloud-master with Apache License 2.0 | 5 votes |
@Override public List<OptUploadFileRespDto> uploadFile(MultipartHttpServletRequest multipartRequest, OptUploadFileReqDto optUploadFileReqDto, LoginAuthDto loginAuthDto, boolean storeDbFlag) { String fileType = optUploadFileReqDto.getFileType(); String filePath = optUploadFileReqDto.getFilePath(); String bucketName = optUploadFileReqDto.getBucketName(); List<OptUploadFileRespDto> result = Lists.newArrayList(); if (PublicUtil.isEmpty(filePath)) { filePath = GlobalConstant.Sys.DEFAULT_FILE_PATH; } try { List<MultipartFile> fileList = multipartRequest.getFiles("file"); if (fileList.isEmpty()) { return result; } for (MultipartFile multipartFile : fileList) { String fileName = multipartFile.getOriginalFilename(); if (PublicUtil.isEmpty(fileName)) { continue; } Preconditions.checkArgument(multipartFile.getSize() <= GlobalConstant.FILE_MAX_SIZE, "上传文件不能大于5M"); InputStream inputStream = multipartFile.getInputStream(); String inputStreamFileType = FileTypeUtil.getType(inputStream); CheckFileUtil.checkFileType(fileType, inputStreamFileType); OptUploadFileRespDto fileInfo; if (storeDbFlag) { fileInfo = this.uploadFile(multipartFile.getBytes(), fileName, fileType, filePath, bucketName, loginAuthDto); } else { fileInfo = optOssService.uploadFile(multipartFile.getBytes(), fileName, filePath, bucketName); } result.add(fileInfo); } } catch (IOException e) { logger.error("上传文件失败={}", e.getMessage(), e); } return result; }
Example 8
Source File: MultipartResolutionDelegate.java From spring-analysis-note with MIT License | 4 votes |
@Nullable public static Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) throws Exception { MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class); boolean isMultipart = (multipartRequest != null || isMultipartContent(request)); if (MultipartFile.class == parameter.getNestedParameterType()) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFile(name) : null); } else if (isMultipartFileCollection(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFiles(name) : null); } else if (isMultipartFileArray(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } if (multipartRequest != null) { List<MultipartFile> multipartFiles = multipartRequest.getFiles(name); return multipartFiles.toArray(new MultipartFile[0]); } else { return null; } } else if (Part.class == parameter.getNestedParameterType()) { return (isMultipart ? request.getPart(name): null); } else if (isPartCollection(parameter)) { return (isMultipart ? resolvePartList(request, name) : null); } else if (isPartArray(parameter)) { return (isMultipart ? resolvePartList(request, name).toArray(new Part[0]) : null); } else { return UNRESOLVABLE; } }
Example 9
Source File: MultipartResolutionDelegate.java From java-technology-stack with MIT License | 4 votes |
@Nullable public static Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) throws Exception { MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class); boolean isMultipart = (multipartRequest != null || isMultipartContent(request)); if (MultipartFile.class == parameter.getNestedParameterType()) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFile(name) : null); } else if (isMultipartFileCollection(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFiles(name) : null); } else if (isMultipartFileArray(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = new StandardMultipartHttpServletRequest(request); } if (multipartRequest != null) { List<MultipartFile> multipartFiles = multipartRequest.getFiles(name); return multipartFiles.toArray(new MultipartFile[0]); } else { return null; } } else if (Part.class == parameter.getNestedParameterType()) { return (isMultipart ? request.getPart(name): null); } else if (isPartCollection(parameter)) { return (isMultipart ? resolvePartList(request, name) : null); } else if (isPartArray(parameter)) { return (isMultipart ? resolvePartList(request, name).toArray(new Part[0]) : null); } else { return UNRESOLVABLE; } }
Example 10
Source File: TemplateManageAction.java From bbs with GNU Affero General Public License v3.0 | 4 votes |
/** * 模板管理 添加 */ @RequestMapping(params="method=add", method=RequestMethod.POST) public String add(ModelMap model,Templates formbean,BindingResult result, MultipartHttpServletRequest request, HttpServletResponse response)throws Exception { //数据校验 this.validator.validate(formbean, result); Templates templates = new Templates(); templates.setName(formbean.getName().trim()); templates.setDirName(formbean.getDirName().trim()); templates.setIntroduction(formbean.getIntroduction()); if (!result.hasErrors()) { //图片上传 List<MultipartFile> files = request.getFiles("uploadImage"); for(MultipartFile file : files) { if(!file.isEmpty()){ //验证文件类型 List<String> formatList = new ArrayList<String>(); formatList.add("gif"); formatList.add("jpg"); formatList.add("jpeg"); formatList.add("bmp"); formatList.add("png"); boolean authentication = FileUtil.validateFileSuffix(file.getOriginalFilename(),formatList); if(authentication){ //取得文件后缀 String ext = FileUtil.getExtension(file.getOriginalFilename()); //文件保存目录 String pathDir = "common"+File.separator+formbean.getDirName()+File.separator; //构建文件名称 String fileName = "templates." + ext; templates.setThumbnailSuffix(ext); //生成文件保存目录 FileUtil.createFolder(pathDir); //保存文件 localFileManage.writeFile(pathDir, fileName,file.getBytes()); }else{ result.rejectValue("thumbnailSuffix","errors.required", new String[]{"图片格式错误"},""); } } break;//只有一个文件上传框 } } if (result.hasErrors()) { return "jsp/template/add_templates"; } List<Layout> layoutList = templateManage.newTemplate(templates.getDirName()); templateService.saveTemplate(templates,layoutList); model.addAttribute("message","添加模板成功");//返回消息 model.addAttribute("urladdress", RedirectPath.readUrl("control.template.list"));//返回消息//返回转向地址 return "jsp/common/message"; }
Example 11
Source File: MultipartResolutionDelegate.java From lams with GNU General Public License v2.0 | 4 votes |
public static Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) throws Exception { MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class); boolean isMultipart = (multipartRequest != null || isMultipartContent(request)); if (MultipartFile.class == parameter.getNestedParameterType()) { if (multipartRequest == null && isMultipart) { multipartRequest = adaptToMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFile(name) : null); } else if (isMultipartFileCollection(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = adaptToMultipartHttpServletRequest(request); } return (multipartRequest != null ? multipartRequest.getFiles(name) : null); } else if (isMultipartFileArray(parameter)) { if (multipartRequest == null && isMultipart) { multipartRequest = adaptToMultipartHttpServletRequest(request); } if (multipartRequest != null) { List<MultipartFile> multipartFiles = multipartRequest.getFiles(name); return multipartFiles.toArray(new MultipartFile[multipartFiles.size()]); } else { return null; } } else if (servletPartClass != null) { if (servletPartClass == parameter.getNestedParameterType()) { return (isMultipart ? RequestPartResolver.resolvePart(request, name) : null); } else if (isPartCollection(parameter)) { return (isMultipart ? RequestPartResolver.resolvePartList(request, name) : null); } else if (isPartArray(parameter)) { return (isMultipart ? RequestPartResolver.resolvePartArray(request, name) : null); } } return UNRESOLVABLE; }
Example 12
Source File: TemplateDevelopController.java From wangmarket with Apache License 2.0 | 4 votes |
/** * 上传preview.jpg图片接口 */ @RequestMapping(value="uploadPreview${url.suffix}", method = RequestMethod.POST) @ResponseBody public UploadFileVO uploadPreview(Model model,HttpServletRequest request){ UploadFileVO uploadFileVO = new UploadFileVO(); if(!haveSiteAuth()){ uploadFileVO.setBaseVO(UploadFileVO.FAILURE, "无权操作"); return uploadFileVO; } if(!clientCheck(request)){ uploadFileVO.setBaseVO(UploadFileVO.FAILURE, "模版开发仅限本地运行使用!"); return uploadFileVO; } Site site = getSite(); //判断一下对方使用的是OSS还是本地存储,如果没用本地存储,提醒用户要使用本地存储的 if(!AttachmentFile.isMode(AttachmentFile.MODE_LOCAL_FILE)){ uploadFileVO.setBaseVO(UploadFileVO.FAILURE, "存储方式请使用服务器本地存储。请按照我们的说明,使用本地一键运行包进行模版开发!"); return uploadFileVO; } if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles("image"); if(imageList.size()>0 && !imageList.get(0).isEmpty()){ MultipartFile multi = imageList.get(0); try { uploadFileVO = AttachmentFile.put(getExportPath()+site.getTemplateName()+"/preview.jpg", multi.getInputStream()); } catch (IOException e) { e.printStackTrace(); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } }else{ uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("oss_uploadNotFile")); } if(uploadFileVO.getResult() == UploadFileVO.SUCCESS){ //上传成功,写日志 AliyunLog.addActionLog(getSiteId(), "模版开发,上传preview.jpg:"+uploadFileVO.getUrl()); } return uploadFileVO; }
Example 13
Source File: UserServiceImpl.java From wangmarket with Apache License 2.0 | 4 votes |
public UploadFileVO updateHeadByOSS(HttpServletRequest request, String formFileName, int maxWidth) { UploadFileVO uploadFileVO = new UploadFileVO(); MultipartFile multipartFile = null; if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> imageList = multipartRequest.getFiles(formFileName); if(imageList.size() == 0){ Log.debug("上传头像时,未发现头像 ------"+Language.show("user_uploadHeadImageNotFind")); uploadFileVO.setResult(UploadFileVO.NOTFILE); uploadFileVO.setInfo(Language.show("user_uploadHeadImageNotFind")); return uploadFileVO; }else{ Log.debug("上传头像,已发现头像的multipartFile"); multipartFile = imageList.get(0); } } if(multipartFile == null || multipartFile.isEmpty()){ uploadFileVO.setBaseVO(BaseVO.FAILURE, Language.show("user_uploadHeadImageNotFind")); Log.debug("上传头像的multipartFile为空,不存在上传的头像 ------"+Language.show("user_uploadHeadImageNotFind")); return uploadFileVO; } User user = ShiroFunc.getUser(); uploadFileVO = OSS.uploadImageByMultipartFile(Global.get("USER_HEAD_PATH"), multipartFile, maxWidth); if(uploadFileVO.getResult() - UploadFileVO.FAILURE == 0){ return uploadFileVO; } User u = sqlDAO.findById(User.class, user.getId()); //删除之前的头像 if(u.getHead() != null && u.getHead().length() > 0 && !u.getHead().equals("default.png")){ AttachmentFile.deleteObject(Global.get("USER_HEAD_PATH")+u.getHead()); } u.setHead(uploadFileVO.getFileName()); sqlDAO.save(u); ShiroFunc.getUser().setHead(uploadFileVO.getFileName()); return uploadFileVO; }
Example 14
Source File: RequestPartMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override @UsesJava8 public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); assertIsMultipartRequest(servletRequest); MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class); Class<?> paramType = parameter.getParameterType(); boolean optional = paramType.getName().equals("java.util.Optional"); if (optional) { parameter.increaseNestingLevel(); paramType = parameter.getNestedParameterType(); } String partName = getPartName(parameter); Object arg; if (MultipartFile.class == paramType) { Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); arg = multipartRequest.getFile(partName); } else if (isMultipartFileCollection(parameter)) { Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); arg = multipartRequest.getFiles(partName); } else if (isMultipartFileArray(parameter)) { Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); List<MultipartFile> files = multipartRequest.getFiles(partName); arg = files.toArray(new MultipartFile[files.size()]); } else if ("javax.servlet.http.Part".equals(paramType.getName())) { assertIsMultipartRequest(servletRequest); arg = servletRequest.getPart(partName); } else if (isPartCollection(parameter)) { assertIsMultipartRequest(servletRequest); arg = new ArrayList<Object>(servletRequest.getParts()); } else if (isPartArray(parameter)) { assertIsMultipartRequest(servletRequest); arg = RequestPartResolver.resolvePart(servletRequest); } else { try { HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, partName); arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType()); WebDataBinder binder = binderFactory.createBinder(request, arg, partName); if (arg != null) { validateIfApplicable(binder, parameter); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); } } mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + partName, binder.getBindingResult()); } catch (MissingServletRequestPartException ex) { // handled below arg = null; } } RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class); boolean isRequired = ((requestPart == null || requestPart.required()) && !optional); if (arg == null && isRequired) { throw new MissingServletRequestPartException(partName); } if (optional) { arg = Optional.ofNullable(arg); } return arg; }
Example 15
Source File: RequestParamMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class); Object arg; if (MultipartFile.class == parameter.getParameterType()) { assertIsMultipartRequest(servletRequest); Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); arg = multipartRequest.getFile(name); } else if (isMultipartFileCollection(parameter)) { assertIsMultipartRequest(servletRequest); Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); arg = multipartRequest.getFiles(name); } else if (isMultipartFileArray(parameter)) { assertIsMultipartRequest(servletRequest); Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?"); List<MultipartFile> multipartFiles = multipartRequest.getFiles(name); arg = multipartFiles.toArray(new MultipartFile[multipartFiles.size()]); } else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) { assertIsMultipartRequest(servletRequest); arg = servletRequest.getPart(name); } else if (isPartCollection(parameter)) { assertIsMultipartRequest(servletRequest); arg = new ArrayList<Object>(servletRequest.getParts()); } else if (isPartArray(parameter)) { assertIsMultipartRequest(servletRequest); arg = RequestPartResolver.resolvePart(servletRequest); } else { arg = null; if (multipartRequest != null) { List<MultipartFile> files = multipartRequest.getFiles(name); if (!files.isEmpty()) { arg = (files.size() == 1 ? files.get(0) : files); } } if (arg == null) { String[] paramValues = webRequest.getParameterValues(name); if (paramValues != null) { arg = (paramValues.length == 1 ? paramValues[0] : paramValues); } } } return arg; }