List of usage examples for org.springframework.web.multipart MultipartHttpServletRequest getFileNames
Iterator<String> getFileNames();
From source file:com.hp.avmon.discovery.service.DiscoveryService.java
/** * MIB//ww w. j a v a 2 s . c om * * @param request * @return * @throws IOException */ public String importMibFile(HttpServletRequest request) throws IOException { String result = StringUtil.EMPTY; HashMap<String, ArrayList<Map<String, String>>> resultMap = new HashMap<String, ArrayList<Map<String, String>>>(); ArrayList<Map<String, String>> files = new ArrayList<Map<String, String>>(); String typeId = request.getParameter("typeId"); String deviceName = request.getParameter("deviceName"); String deviceDesc = request.getParameter("deviceDesc"); String factory = request.getParameter("factory"); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // ? String templatePath = Config.getInstance().getMibfilesUploadPath(); File dirPath = new File(templatePath); if (!dirPath.exists()) { dirPath.mkdirs(); } Map<String, String> fileMap; for (Iterator<String> it = multipartRequest.getFileNames(); it.hasNext();) { String fileName = (String) it.next(); fileMap = new HashMap<String, String>(); CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile(fileName); if (file != null && file.getSize() != 0) { String sep = System.getProperty("file.separator"); File uploadedFile = new File(dirPath + sep + file.getOriginalFilename()); FileCopyUtils.copy(file.getBytes(), uploadedFile); try { insertMibFileTb(file.getOriginalFilename(), typeId, deviceName, deviceDesc, factory); MibFileParserDB mibFileParser = new MibFileParserDB(dirPath + sep + file.getOriginalFilename()); mibFileParser.parseMib(jdbcTemplate); } catch (MibLoaderException e) { fileMap.put("error", "Mib"); logger.error(e.getMessage()); } catch (DataAccessException e1) { logger.error(e1.getMessage()); fileMap.put("error", "??,?"); } catch (Exception e2) { logger.error(this.getClass().getName() + e2.getMessage()); fileMap.put("error", ",?"); } } fileMap.put("url", ""); fileMap.put("thumbnailUrl", ""); fileMap.put("name", file.getOriginalFilename()); fileMap.put("type", "image/jpeg"); fileMap.put("size", file.getSize() + ""); fileMap.put("deleteUrl", ""); fileMap.put("deleteType", "DELETE"); files.add(fileMap); } resultMap.put("files", files); result = JackJson.fromObjectToJson(resultMap); logger.debug(result); return result; }
From source file:architecture.ee.web.spring.controller.SecureWebMgmtDataController.java
@RequestMapping(value = "/mgmt/logo/upload.json", method = RequestMethod.POST) @ResponseBody/*from w w w . jav a2s . c o m*/ public Result uploadLogoImage( @RequestParam(value = "objectType", defaultValue = "1", required = false) Integer objectType, @RequestParam(value = "objectId", defaultValue = "0", required = false) Long objectId, MultipartHttpServletRequest request) throws NotFoundException, IOException { User user = SecurityHelper.getUser(); if (objectId == 0) { if (objectType == 1) { objectId = user.getCompanyId(); } else if (objectType == 30) { objectId = WebSiteUtils.getWebSite(request).getWebSiteId(); } } Iterator<String> names = request.getFileNames(); while (names.hasNext()) { String fileName = names.next(); log.debug(fileName); MultipartFile mpf = request.getFile(fileName); InputStream is = mpf.getInputStream(); log.debug("file name: " + mpf.getOriginalFilename()); log.debug("file size: " + mpf.getSize()); log.debug("file type: " + mpf.getContentType()); log.debug("file class: " + is.getClass().getName()); LogoImage logo = logoManager.createLogoImage(); logo.setFilename(mpf.getName()); logo.setImageContentType(mpf.getContentType()); logo.setImageSize((int) mpf.getSize()); logo.setObjectType(objectType); logo.setObjectId(objectId); logo.setPrimary(true); logoManager.addLogoImage(logo, mpf.getInputStream()); } return Result.newResult(); }
From source file:com.daoke.mobileserver.user.controller.UserController.java
/** * ?/*from ww w .j a va2 s.co m*/ * * @param appKey * @param accountID * @param request * @return */ @RequestMapping("/uploadHeadImage") public @ResponseBody CommonJsonResult uploadImage(@RequestParam String appKey, @RequestParam String accountID, HttpServletRequest request) { CommonJsonResult res = new CommonJsonResult(); String appkey = ConstantsUtil.getAppKey(appKey); String secret = ConstantsUtil.getSecret(appKey); String headImageUrl = ""; try { //url CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( request.getSession().getServletContext()); if (multipartResolver.isMultipart(request)) { MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; Iterator<String> iter = multiRequest.getFileNames(); while (iter.hasNext()) { MultipartFile file = multiRequest.getFile(iter.next()); String fileResultUrl = customService.saveFile(appkey, secret, file, saveFile); CommonJsonResult fileResult = (CommonJsonResult) JsonMapper.fromJson(fileResultUrl, CommonJsonResult.class); Map<String, String> param = (Map<String, String>) fileResult.getRESULT(); headImageUrl = param.get("url"); break; } } if (headImageUrl != null) { if (userGradeService.uploadHeadImage(accountID, headImageUrl) > 0) { res.setERRORCODE(ConstantsUtil.ERRORCODE_OK); Map<String, String> map = new HashMap<String, String>(); map.put("headImageUrl", headImageUrl); res.setRESULT(map); } else { res.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR); res.setRESULT("?"); } } } catch (Exception e1) { e1.printStackTrace(); logger.error("?:" + e1.getMessage()); res.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR); res.setRESULT("?"); } return res; }
From source file:com.opendesign.controller.ProductController.java
/** * ??() ?//*from w w w . jav a2 s .com*/ * * @param product * @param request * @param saveType * @return * @throws Exception */ private JsonModelAndView saveProduct(DesignWorkVO product, MultipartHttpServletRequest request, int saveType) throws Exception { /* * ?? ? ? */ boolean isUpdate = saveType == SAVE_TYPE_UPDATE; Map<String, Object> resultMap = new HashMap<String, Object>(); UserVO loginUser = CmnUtil.getLoginUser(request); if (loginUser == null || !StringUtil.isNotEmpty(loginUser.getSeq())) { resultMap.put("result", "100"); return new JsonModelAndView(resultMap); } /* ? ? */ if (isUpdate) { DesignWorkVO prevProduct = designerService.getDesignWork(product.getSeq()); if (!loginUser.getSeq().equals(prevProduct.getMemberSeq())) { resultMap.put("result", "101"); return new JsonModelAndView(resultMap); } } /* * ? ? */ MultipartFile fileUrlFile = request.getFile("fileUrlFile"); if (fileUrlFile != null) { String fileName = fileUrlFile.getOriginalFilename().toLowerCase(); if (!(fileName.endsWith(".jpg") || fileName.endsWith(".png"))) { resultMap.put("result", "202"); return new JsonModelAndView(resultMap); } } else { /* ? ? . */ if (!isUpdate) { resultMap.put("result", "201"); return new JsonModelAndView(resultMap); } } /* * license */ String license01 = request.getParameter("license01"); String license02 = request.getParameter("license02"); String license03 = request.getParameter("license03"); String license = license01 + license02 + license03; product.setLicense(license); //?? ?///// String stem = request.getParameter("origin"); if (stem == null) { product.setOriginSeq("0"); } else { product.setOriginSeq(stem); } ////////////////////////////// /* * ?? ? "0" */ String point = request.getParameter("point"); point = String.valueOf(CmnUtil.getIntValue(point)); //null--> 0 product.setPoint(point); /* * ? ? */ List<MultipartFile> productFileList = new ArrayList<MultipartFile>(); List<MultipartFile> openSourceFileList = new ArrayList<MultipartFile>(); Iterator<String> iterator = request.getFileNames(); while (iterator.hasNext()) { String fileNameKey = iterator.next(); MultipartFile reqFile = request.getFile(fileNameKey); if (reqFile != null) { boolean existProuductFile = fileNameKey.startsWith("productFile"); boolean existOpenSourceFile = fileNameKey.startsWith("openSourceFile"); if (existProuductFile || existOpenSourceFile) { long fileSize = reqFile.getSize(); if (fileSize > LIMIT_FILE_SIZE) { resultMap.put("result", "203"); resultMap.put("fileName", reqFile.getOriginalFilename()); return new JsonModelAndView(resultMap); } if (existProuductFile) { productFileList.add(reqFile); } if (existOpenSourceFile) { openSourceFileList.add(reqFile); } } } } product.setMemberSeq(loginUser.getSeq()); /* * ?? */ String fileUploadDir = CmnUtil.getFileUploadDir(request, FileUploadDomain.PRODUCT); File thumbFile = null; if (fileUrlFile != null) { String saveFileName = UUID.randomUUID().toString(); thumbFile = CmnUtil.saveFile(fileUrlFile, fileUploadDir, saveFileName); String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, thumbFile); product.setThumbUri(fileUploadDbPath); } /* * ??() */ List<DesignPreviewImageVO> productList = new ArrayList<DesignPreviewImageVO>(); List<String> productFilePaths = new ArrayList<>(); for (MultipartFile aFile : productFileList) { String saveFileName = UUID.randomUUID().toString(); File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName); productFilePaths.add(file.getAbsolutePath()); String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file); DesignPreviewImageVO productFile = new DesignPreviewImageVO(); productFile.setFilename(aFile.getOriginalFilename()); productFile.setFileUri(fileUploadDbPath); productList.add(productFile); } product.setImageList(productList); /* * */ List<DesignWorkFileVO> openSourceList = new ArrayList<DesignWorkFileVO>(); for (MultipartFile aFile : openSourceFileList) { String saveFileName = UUID.randomUUID().toString(); File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName); String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file); //openSourceFile? ??? client? . String filenameOpenSourceFile = StringUtils .stripToEmpty(request.getParameter("filename_" + aFile.getName())); DesignWorkFileVO openSourceFile = new DesignWorkFileVO(); openSourceFile.setFilename(filenameOpenSourceFile); openSourceFile.setFileUri(fileUploadDbPath); openSourceList.add(openSourceFile); } product.setFileList(openSourceList); /* * ??/? ? ? ? * ?? ? ? ? ? ? */ String thumbFilePath = ""; if (thumbFile != null) { thumbFilePath = thumbFile.getAbsolutePath(); } ThumbnailManager.resizeNClone4DesignWork(thumbFilePath, productFilePaths); /* * */ String tag = request.getParameter("tag"); if (StringUtil.isNotEmpty(tag)) { String[] tags = tag.split(","); int addIndex = 0; StringBuffer tagBuffer = new StringBuffer(); for (String aTag : tags) { if (StringUtil.isNotEmpty(aTag)) { aTag = aTag.trim(); tagBuffer.append(aTag); tagBuffer.append("|"); addIndex++; } if (addIndex >= 5) { break; } } if (addIndex > 0) { tagBuffer.insert(0, "|"); tag = tagBuffer.toString(); } } product.setTags(tag); String currentDate = Day.getCurrentTimestamp().substring(0, 12); product.setRegisterTime(currentDate); product.setUpdateTime(currentDate); String[] categoryCodes = request.getParameterValues("categoryCodes"); /* * */ if (isUpdate) { String[] removeProductSeqs = request.getParameterValues("removeProductSeq"); String[] removeOpenSourceSeqs = request.getParameterValues("removeOpenSourceSeq"); int projectSeq = service.updateProduct(product, categoryCodes, removeProductSeqs, removeOpenSourceSeqs); } else { int projectSeq = service.insertProduct(product, categoryCodes); } resultMap.put(RstConst.P_NAME, RstConst.V_SUCESS); return new JsonModelAndView(resultMap); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileUploadX.do") public void fileUploadX(HttpServletRequest request, HttpServletResponse response, SessionStatus status) throws Exception { //System.out.println(" ? uuid--"+request.getParameter("uuid")); String chkType = request.getHeader("Content-Type"); if (chkType == null) { return;/*ww w . j a va 2s. c o m*/ } request.setCharacterEncoding("utf-8"); String contextRealPath = request.getSession().getServletContext().getRealPath("/"); String PATH = request.getParameter("PATH"); String savePath = contextRealPath + PATH; // System.out.println("savePath------@@-----"+savePath); // int maxSize = 500 * 1024 * 1024; // ? ? 500MB() PlatformData resData = new PlatformData(); VariableList resVarList = resData.getVariableList(); String sMsg = " A "; try { MultipartHttpServletRequest msReq = (MultipartHttpServletRequest) request; Iterator<String> filesd = msReq.getFileNames(); String dir = request.getRealPath("images/egovframework/board_img"); while (filesd.hasNext()) { sMsg += "D "; //String name = (String)files.nextElement(); String name = filesd.next(); // System.out.println("? ^^-----"+name); MultipartFile mfile = msReq.getFile(name); //? String genId = UUID.randomUUID().toString(); //? String originalFileName = mfile.getOriginalFilename(); //? String saveFileName = genId; // System.out.println("???="+ originalFileName); System.out.println("??=" + saveFileName); String savePathh = dir + "/" + saveFileName; mfile.transferTo(new File(savePathh)); System.out.println(name + "??"); System.out.println("? ?-" + genId); //?? SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) mfile.getSize()); vo.setiUrl(savePathh); vo.setiUuid(request.getParameter("uuid")); sampleService.uploadImg(vo); status.setComplete(); } resVarList.add("ErrorCode", 200); resVarList.add("ErrorMsg", "SUCC"); } catch (Exception e) { resVarList.add("ErrorCode", 500); resVarList.add("ErrorMsg", sMsg + " " + e); } HttpPlatformResponse res = new HttpPlatformResponse(response); res.setData(resData); res.sendData(); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileUploadX2.do") public void fileUploadX2(HttpServletRequest request, HttpServletResponse response, SessionStatus status) throws Exception { //System.out.println(" ? uuid--"+request.getParameter("uuid")); String chkType = request.getHeader("Content-Type"); if (chkType == null) { return;// w w w .jav a 2s.co m } request.setCharacterEncoding("utf-8"); String contextRealPath = request.getSession().getServletContext().getRealPath("/"); String PATH = request.getParameter("PATH"); String savePath = contextRealPath + PATH; // System.out.println("savePath------@@-----"+savePath); // int maxSize = 500 * 1024 * 1024; // ? ? 500MB() PlatformData resData = new PlatformData(); VariableList resVarList = resData.getVariableList(); String sMsg = " A "; try { MultipartHttpServletRequest msReq = (MultipartHttpServletRequest) request; Iterator<String> filesd = msReq.getFileNames(); String dir = request.getRealPath("images/egovframework/board_img"); while (filesd.hasNext()) { sMsg += "D "; //String name = (String)files.nextElement(); String name = filesd.next(); // System.out.println("? ^^-----"+name); MultipartFile mfile = msReq.getFile(name); //? String genId = UUID.randomUUID().toString(); //? String originalFileName = mfile.getOriginalFilename(); //? String saveFileName = genId; // System.out.println("???="+ originalFileName); System.out.println("??=" + saveFileName); String savePathh = dir + "/" + saveFileName; mfile.transferTo(new File(savePathh)); System.out.println(name + "??"); System.out.println("? ?-" + genId); //?? SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) mfile.getSize()); vo.setiUrl(savePathh); vo.setiUuid("thumbnail"); sampleService.uploadImg(vo); //? ? //updateThumbnail Product pVO = new Product(); pVO.setP_uuid(request.getParameter("uuid")); System.out.println(" uuid-" + request.getParameter("uuid")); String thumbnail = "http://localhost:8778/sample/images/egovframework/board_img/" + saveFileName; pVO.setP_thumbnail(thumbnail); sampleService.updateThumbnail(pVO); status.setComplete(); } resVarList.add("ErrorCode", 200); resVarList.add("ErrorMsg", "SUCC"); } catch (Exception e) { resVarList.add("ErrorCode", 500); resVarList.add("ErrorMsg", sMsg + " " + e); } HttpPlatformResponse res = new HttpPlatformResponse(response); res.setData(resData); res.sendData(); }
From source file:com.emaxcore.emaxdata.modules.testdrive.pub.web.TestdriveUploadSignatureController.java
/** * ???????/* w w w .j av a2 s . com*/ * * @param model * @param request * @param response * @return * @throws Exception */ @RequestMapping(value = "uploadSignature") @ResponseBody public String uploadSignature(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws IOException { if (isDebugLogger) { logger.debug(" ??------uploadSignature-------start--------"); } response.setContentType(TestdrivePubConstant.ENCODED); Map<?, ?> jsonMap = null; // ? // ??????? StringBuilder idcardDriveProtocol = new StringBuilder(); // ??????? CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( request.getSession().getServletContext()); if (multipartResolver.isMultipart(request)) { MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; // json String jsonDataStr = multiRequest.getParameter(TestdrivePubConstant.VALUE); if (Global.isSecretMode()) { if (isDebugLogger) { logger.debug("app ?---------- Start------{}---------", jsonDataStr); } AES256EncryptionUtils des = AES256EncryptionUtils.getInstance(); String jsonData = des.decrypt(jsonDataStr); jsonMap = JsonMapper.nonDefaultMapper().fromJson(jsonData, HashMap.class); } else { jsonMap = JsonMapper.nonDefaultMapper().fromJson(jsonDataStr, HashMap.class); } if (isDebugLogger) { logger.debug("uploadSignature?----------jsonMap---{}---------", jsonMap); } // ? TestDriveApplyInfo testDriveApplyInfo = new TestDriveApplyInfo(); //??-- String userFristName = TestdrivePubUtils.readJsonMapValue("fristName", jsonMap); if (StringUtils.isBlank(userFristName)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "fristName", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setFirstName(userFristName); //??-- String userLastName = TestdrivePubUtils.readJsonMapValue("lastName", jsonMap); if (StringUtils.isBlank(userLastName)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "lastName", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setLastName(userLastName); //?? String userName = userFristName + userLastName; testDriveApplyInfo.setName(userName); //telephone String telephone = TestdrivePubUtils.readJsonMapValue("telephone", jsonMap); if (StringUtils.isBlank(telephone)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "telephone", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setMobile(telephone); //appellation String appellation = TestdrivePubUtils.readJsonMapValue("appellation", jsonMap); if (StringUtils.isBlank(appellation)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "appellation", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setSex(appellation); //motorcycleType String motorcycleType = TestdrivePubUtils.readJsonMapValue("motorcycleType", jsonMap); if (StringUtils.isBlank(motorcycleType)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "motorcycleType", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setVehiclesType(motorcycleType); // String widthName = TestdrivePubUtils.readJsonMapValue("userName", jsonMap); if (StringUtils.isBlank(widthName)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "userName", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setWidthName(widthName); // ?MD5 String idCarMD5Hash = TestdrivePubUtils.readJsonMapValue("IDCarMD5Hash", jsonMap); // MD5 String driveMD5Hash = TestdrivePubUtils.readJsonMapValue("driveMD5Hash", jsonMap); // ????MD5 String protocolMD5Hash = TestdrivePubUtils.readJsonMapValue("protocolMD5Hash", jsonMap); // ??? String cidNumber = TestdrivePubUtils.readJsonMapValue("IDNumber", jsonMap); if (StringUtils.isBlank(cidNumber)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "???", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } testDriveApplyInfo.setIdNumber(cidNumber); // ?D:\apache-tomcat-7.0.47\webapps\benz String path = TestdrivePubUtils.getRealPath(request); // ????/mnt/sdc1/data/benzsite String savePath = Global.getUserfilesBaseDir(); // ?/userfiles/app/login ??login String signaturePicAddressPre = TestdrivePubConstant.APP_USER_FILES_PATH + userName; String filePath = ""; // /benz String projectPath = request.getContextPath(); if (StringUtils.isBlank(savePath)) { // ?D:\apache-tomcat-7.0.47\webapps\benz/userfiles/app/login filePath = path + signaturePicAddressPre; } else { filePath = savePath + projectPath + signaturePicAddressPre; } Iterator<String> iter = multiRequest.getFileNames(); while (iter.hasNext()) { MultipartFile file = multiRequest.getFile((String) iter.next()); if (file != null && !file.isEmpty()) { String fileName = file.getOriginalFilename(); FileEmaxDataUtils.createDirectory(filePath); String fileNamePath = filePath + File.separator + fileName; String relativePath = projectPath + signaturePicAddressPre + File.separator + fileName; File localFile = new File(fileNamePath); file.transferTo(localFile); String md5Hash = MD5Utils.getFileMD5String(localFile); // ? if (fileName.startsWith(TestdrivePubConstant.IDCARD_PREFIX)) { if (!idCarMD5Hash.equals(md5Hash)) { idcardDriveProtocol.append(card); boolean deletFlag = localFile.delete(); if (deletFlag) { logger.info("??"); } } else { testDriveApplyInfo.setIdentityCardScanningFile(relativePath); } } // if (fileName.startsWith(TestdrivePubConstant.DRIVE_PREFIX)) { if (!driveMD5Hash.equals(md5Hash)) { idcardDriveProtocol.append(drive); boolean deletFlag = localFile.delete(); if (deletFlag) { logger.info("?!"); } } else { testDriveApplyInfo.setDriversLicenseScanningFile(relativePath); } } // ???? if (fileName.startsWith(TestdrivePubConstant.PROTOCOL_PREFIX)) { if (!protocolMD5Hash.equals(md5Hash)) { idcardDriveProtocol.append(protocol); boolean deletFlag = localFile.delete(); if (deletFlag) { logger.info("?????"); } } else { testDriveApplyInfo.setNumberSignature(relativePath); } } } } // ????1?1? String driveStatus = testDriveApplyInfo.getDriveStatus(); if ((StringUtils.isNotBlank(driveStatus) && (Integer.parseInt(driveStatus) < 1)) || StringUtils.isBlank(driveStatus)) { testDriveApplyInfo.setDriveStatus("1");// ?? } testDriveApplyInfoService.save(testDriveApplyInfo); } else { jsonMap = this.saveJson(TestdrivePubConstant.SUCCESS_STATE, "??", ""); return TestdrivePubUtils.loggerJsonMap(jsonMap); } if (StringUtils.isNotBlank(idcardDriveProtocol)) { jsonMap = this.saveJson(TestdrivePubConstant.ERROR_STATE, "", idcardDriveProtocol.toString()); return TestdrivePubUtils.loggerJsonMap(jsonMap); } else { jsonMap = this.saveJson(TestdrivePubConstant.SUCCESS_STATE, TestdrivePubConstant.SUCCESS, idcardDriveProtocol.toString()); } String appJson = TestdrivePubUtils.loggerJsonMap(jsonMap); if (isDebugLogger) { logger.debug("??--uploadSignature----end---"); } return appJson; }
From source file:org.cloud.mblog.utils.FileUtil.java
/** * Ckeditor?// w w w. ja v a 2s .c o m * * @param request * @return */ public static String processUploadPostForCkeditor(HttpServletRequest request) { LocalDateTime now = LocalDateTime.now(); String realFolder = LOCALROOT + getImageRelativePathByDate(now); String urlPath = getImageUrlPathByDate(now); DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); diskFileItemFactory.setRepository(new File(realFolder)); ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory); servletFileUpload.setFileSizeMax(MAX_FILE_SIZE); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Iterator<String> fileNameIter = multipartRequest.getFileNames(); try { while (fileNameIter.hasNext()) { MultipartFile mr = multipartRequest.getFile(fileNameIter.next()); String sourceFileName = mr.getOriginalFilename(); if (StringUtils.isNotBlank(sourceFileName)) { String fileType = sourceFileName.substring(sourceFileName.lastIndexOf(".") + 1); if (ALLOWEXT.contains(fileType)) { String filename = getDateTypeFileName(now, fileType); File targetFile = new File(realFolder + File.separator + filename); logger.info("Upload file path: " + targetFile.getAbsolutePath()); mr.transferTo(targetFile); return urlPath + "/" + filename; } else { logger.error("?: " + fileType); return ""; } } } } catch (IOException e) { logger.error("error", e); } return ""; }
From source file:org.craftercms.social.controllers.rest.v3.comments.ProfileHelperController.java
@RequestMapping(value = "/avatar/{profileId}", method = RequestMethod.POST) @ResponseBody// w w w .j av a 2s . c o m public Profile getProfileAvatar(MultipartHttpServletRequest request, HttpServletResponse response, @PathVariable("profileId") String profileId) throws IOException, ProfileException { final Profile profile = SocialSecurityUtils.getCurrentProfile(); if (profile != null && !profile.getUsername().equalsIgnoreCase(SocialSecurityUtils.ANONYMOUS)) { final Iterator<String> files = request.getFileNames(); String fileName = null; if (files.hasNext()) { fileName = files.next(); } if (!StringUtils.isBlank(fileName)) { final MultipartFile avatar = request.getFile(fileName); profileService.addProfileAttachment(profile.getId().toString(), AVATAR + "." + FilenameUtils.getExtension(avatar.getOriginalFilename()).toLowerCase(), avatar.getInputStream()); } return profile; } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; } }
From source file:org.davidmendoza.fileUpload.web.ImageController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody Map upload(MultipartHttpServletRequest request, HttpServletResponse response) { log.debug("uploadPost called"); Iterator<String> itr = request.getFileNames(); MultipartFile mpf;/*from ww w .jav a 2 s.co m*/ List<Image> list = new LinkedList<>(); while (itr.hasNext()) { mpf = request.getFile(itr.next()); log.debug("Uploading {}", mpf.getOriginalFilename()); String newFilenameBase = UUID.randomUUID().toString(); String originalFileExtension = mpf.getOriginalFilename() .substring(mpf.getOriginalFilename().lastIndexOf(".")); String newFilename = newFilenameBase + originalFileExtension; String storageDirectory = fileUploadDirectory; String contentType = mpf.getContentType(); File newFile = new File(storageDirectory + "/" + newFilename); try { mpf.transferTo(newFile); BufferedImage thumbnail = Scalr.resize(ImageIO.read(newFile), 290); String thumbnailFilename = newFilenameBase + "-thumbnail.png"; File thumbnailFile = new File(storageDirectory + "/" + thumbnailFilename); ImageIO.write(thumbnail, "png", thumbnailFile); Image image = new Image(); image.setName(mpf.getOriginalFilename()); image.setThumbnailFilename(thumbnailFilename); image.setNewFilename(newFilename); image.setContentType(contentType); image.setSize(mpf.getSize()); image.setThumbnailSize(thumbnailFile.length()); image = imageDao.create(image); image.setUrl("/picture/" + image.getId()); image.setThumbnailUrl("/thumbnail/" + image.getId()); image.setDeleteUrl("/delete/" + image.getId()); image.setDeleteType("DELETE"); list.add(image); } catch (IOException e) { log.error("Could not upload file " + mpf.getOriginalFilename(), e); } } Map<String, Object> files = new HashMap<>(); files.put("files", list); return files; }