List of usage examples for org.springframework.web.multipart MultipartFile getSize
long getSize();
From source file:com.glaf.core.util.UploadUtils.java
/** * ????/*from w w w . j a va 2 s. c om*/ * * @param request * @param fileParam * @param fileType * ?:jpg,gif,png,jpeg,swf * @param fileSize * MB?? * @return status=0 ?<br/> * status=1 <br/> * status=2 ?<br/> */ public static int getUploadStatus(HttpServletRequest request, String fileParam, String fileType, long fileSize) { int status = 0; MultipartFile mFile = getMultipartFile(request, fileParam); if (!mFile.isEmpty()) { String ext = FileUtils.getFileExt(mFile.getOriginalFilename()); if (!StringUtils.containsIgnoreCase(fileType, ext)) { status = 1; } long size = mFile.getSize(); if (fileSize != -1 && size > FileUtils.MB_SIZE * fileSize) { status = 2; } } return status; }
From source file:com.ylife.goods.model.UploadUtil.java
/** * ????,SpringMVC/* ww w . ja v a 2 s . co m*/ * * @param muFile * MultipartFile * @return ?? */ private static boolean checkFileForSpringUpload(MultipartFile muFile) { boolean bool = true; // ? if (muFile.getSize() > maxSize) { //LOGGER.error("=============>" + muFile.getOriginalFilename() + "??"); bool = false; } String fileName = muFile.getOriginalFilename(); // ?? String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); if (!Arrays.<String>asList(extMap.get(IMAGE).split(",")).contains(fileExt)) { //LOGGER.error("" + muFile.getOriginalFilename() + "??????\n??" + extMap.get(IMAGE) + "?"); bool = false; } return bool; }
From source file:com.ylife.goods.model.UploadUtil.java
/** * ??/*from w w w . j a v a2 s. c o m*/ * * @param muFile * MultipartFile * @param request * HttpServletRequest * @return ???Map * @throws java.io.IOException * */ public static synchronized Map<String, String> testUpYun(MultipartFile muFile, HttpServletRequest request) throws IOException { Map<String, String> map = new HashMap<String, String>(); UpyunConf upConf = sysHelperMapper.selectUpyunConf(); if (muFile != null && muFile.getSize() != 0) { // ??? if (!checkFileForSpringUpload(muFile)) { throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1); } // ??? if (upConf != null) { // ??? map = uploadImgUpyun.testUpYun(muFile, upConf); } return map; } else { return null; } }
From source file:com.ylife.goods.model.UploadUtil.java
/** * ?//w w w .j a va 2 s .co m * * @param muFile * * @param request * HttpServletRequest * @return String */ public static synchronized String uploadFileOne(MultipartFile muFile, HttpServletRequest request) { Map<String, String> map = new HashMap<String, String>(); UpyunConf upConf = sysHelperMapper.selectUpyunConf(); FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr(); if (muFile != null && muFile.getSize() != 0) { // ??? if (!checkFileForSpringUpload(muFile)) { throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1); } // ??? if (upConf != null && "1".equals(upConf.getUsedStatus())) { // ??? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf); } else { // FastDFS map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } else { // Java? // ?? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgJava.uploadForOldAndSmall(muFile); } else { // FastDFS map = uploadImgJava.uploadForOldAndSmallSaveFastDFS(muFile); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } return map.get("oldimg"); } else { return null; } }
From source file:com.ylife.goods.model.UploadUtil.java
/** * ?// www . j a v a2 s . c o m * * @param muFile * * @param request * HttpServletRequest * @return String */ public static synchronized String uploadFileCustomerHeadOne(MultipartFile muFile, HttpServletRequest request) { Map<String, String> map = new HashMap<String, String>(); UpyunConf upConf = sysHelperMapper.selectUpyunConf(); FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr(); if (muFile != null && muFile.getSize() != 0) { // ??? if (!checkFileForSpringUpload(muFile)) { throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1); } // ??? if (upConf != null && "1".equals(upConf.getUsedStatus())) { // ??? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf); } else { // FastDFS map = uploadImgUpyun.uploadForOldAndSmall(muFile, upConf); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } else { // Java? // ?? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgJava.uploadForOldAndSmall(muFile); } else { // FastDFS map = uploadImgJava.uploadForABCSizeSaveFastDFS(muFile); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } return map.get("oldimg"); } else { return null; } }
From source file:com.ylife.goods.model.UploadUtil.java
/** * key//from w w w . ja v a2 s . com * * @param muFile * * @param request * HttpServletRequest * @return Map key{0,1,2,oldimg} 0? 1 2 oldimg */ public static synchronized Map<String, String> uploadFile(MultipartFile muFile, HttpServletRequest request) { Map<String, String> map = new HashMap<String, String>(); UpyunConf upConf = sysHelperMapper.selectUpyunConf(); FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr(); if (muFile != null && muFile.getSize() != 0) { // ??? if (!checkFileForSpringUpload(muFile)) { throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1); } // ??? if (upConf != null && "1".equals(upConf.getUsedStatus())) { // ??? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgUpyun.uploadForABCSize(muFile, upConf); } else { // FastDFS map = uploadImgUpyun.uploadForABCSize(muFile, upConf); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } else { // Java? // ?? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgJava.uploadForABCSize(muFile); } else { // FastDFS map = uploadImgJava.uploadForABCSizeSaveFastDFS(muFile); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } return map; } else { return null; } }
From source file:com.ylife.goods.model.UploadUtil.java
/** * ,?key//from www . j a va 2s . c om * * @param muFile * * @param request * HttpServletRequest * @return Map key{width...,oldimg} oldimg */ public static synchronized Map<String, String> uploadFileByWidth(MultipartFile muFile, HttpServletRequest request) { Map<String, String> map = new HashMap<String, String>(); UpyunConf upConf = sysHelperMapper.selectUpyunConf(); FastDFSInfo fastdfs = fastDFSService.getFastDFSInfoByCurr(); if (muFile != null && muFile.getSize() != 0) { // ??? if (!checkFileForSpringUpload(muFile)) { throw new RuntimeException("" + muFile.getOriginalFilename() + LOGGERINFO1); } // ??? if (upConf != null && "1".equals(upConf.getUsedStatus())) { // ??? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgUpyun.uploadForAllSize(muFile, upConf); } else { // FastDFS map = uploadImgUpyun.uploadForAllSize(muFile, upConf); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } else { // Java? // ?? if (null == fastdfs || "0".equals(fastdfs.getUserd())) { map = uploadImgJava.uploadForAllSize(muFile); } else { // FastDFS map = uploadImgJava.uploadForABCSizeSaveFastDFSWidth(muFile); map = uploadImgFastDFS.saveToFastDFS(map, fastdfs); } } return map; } else { return null; } }
From source file:com.asual.summer.sample.convert.MultipartFileToImageConverter.java
@Override public Image convert(MultipartFile source) { if (source.getSize() != 0 && mimeTypes.contains(source.getContentType())) { try {//from www . j ava 2 s . c o m return new Image(source); } catch (Exception e) { logger.error(e.getMessage(), e); } } return null; }
From source file:com.slyak.services.file.domain.FileInfo.java
@SneakyThrows public FileInfo(MultipartFile file) { this.size = file.getSize(); this.name = file.getName(); this.contentType = file.getContentType(); this.inputStream = file.getInputStream(); }
From source file:se.gothiaforum.validator.actorsform.ImageValidator.java
/** * Validate if the image have valid size, file suffix and mime. * //from ww w .jav a 2s .co m * @param multipartFile * the multipart file * @param errors * the errors */ public void validate(MultipartFile multipartFile, List<String> errors) { if (multipartFile.getSize() > IMAGE_MIN_SIZE && multipartFile.getSize() < IMAGE_MAX_SIZE) { String originalFileName = multipartFile.getOriginalFilename(); String contentType = multipartFile.getContentType(); if (!"image/jpeg".equals(contentType) && !"image/png".equals(contentType) && !"image/x-png".equals(contentType) && !"image/pjpeg".equals(contentType) && !"image/gif".equals(contentType)) { errors.add("wrong-type-of-content-type"); } int fileExtensionIndex = originalFileName.lastIndexOf("."); String fileExtension = originalFileName.substring((fileExtensionIndex + 1), originalFileName.length()); if (!fileExtension.equals("png") && !fileExtension.equals("jpg") && !fileExtension.equals("gif")) { errors.add("wrong-type-of-file-extension"); } } else { errors.add("wrong-size-on-file"); } }