List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:org.magnum.dataup.MainController.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id, final @RequestParam("data") MultipartFile videoData, HttpServletResponse response) { try {//from w ww. ja v a 2 s .co m if (!videos.containsKey(id)) { response.setStatus(404); return new VideoStatus(VideoState.READY); } //saveSomeVideo(videos.get(id), (MultipartFile) videoData.getInputStream()); videoDataMgr = VideoFileManager.get(); videoDataMgr.saveVideoData(videos.get(id), videoData.getInputStream()); } catch (IOException e) { e.printStackTrace(); } return new VideoStatus(VideoState.READY); }
From source file:io.lavagna.web.api.CardDataController.java
@ExpectPermission(Permission.CREATE_FILE) @RequestMapping(value = "/api/card/{cardId}/file", method = RequestMethod.POST) @ResponseBody//w w w.ja v a 2 s. co m public List<String> uploadFiles(@PathVariable("cardId") int cardId, @RequestParam("files") List<MultipartFile> files, User user, HttpServletResponse resp) throws IOException { LOG.debug("Files uploaded: {}", files.size()); if (!ensureFileSize(files)) { resp.setStatus(422); return Collections.emptyList(); } List<String> digests = new ArrayList<>(); for (MultipartFile file : files) { Path p = Files.createTempFile("lavagna", "upload"); try (InputStream fileIs = file.getInputStream()) { Files.copy(fileIs, p, StandardCopyOption.REPLACE_EXISTING); String digest = DigestUtils.sha256Hex(Files.newInputStream(p)); String contentType = file.getContentType() != null ? file.getContentType() : "application/octet-stream"; boolean result = cardDataService.createFile(file.getOriginalFilename(), digest, file.getSize(), cardId, Files.newInputStream(p), contentType, user, new Date()).getLeft(); if (result) { LOG.debug("file uploaded! size: {}, original name: {}, content-type: {}", file.getSize(), file.getOriginalFilename(), file.getContentType()); digests.add(digest); } } finally { Files.delete(p); LOG.debug("deleted temp file {}", p); } } eventEmitter.emitUploadFile(cardRepository.findBy(cardId).getColumnId(), cardId); return digests; }
From source file:com.zte.gu.webtools.web.rfa.RfaController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView scan(@RequestParam(required = true) MultipartFile ruFile, HttpSession session) { ModelAndView modelAndView = new ModelAndView("rfa/rfaScan"); if (ruFile.isEmpty()) { modelAndView.getModelMap().addAttribute("error", "RU?"); }// ww w. j a v a 2 s. c om if (!ACCEPT_TYPES.contains(ruFile.getContentType())) { modelAndView.getModelMap().addAttribute("error", "RU???"); } InputStream ruInput = null; try { ruInput = ruFile.getInputStream(); File tempZipFile = rfaService.exportXml(ruInput); //? if (tempZipFile != null) { session.setAttribute("filePath", tempZipFile.getPath()); session.setAttribute("fileName", "rfa.zip"); modelAndView.setViewName("redirect:/download"); } } catch (Exception e) { LoggerFactory.getLogger(RfaController.class).warn("download error,", e); modelAndView.getModelMap().addAttribute("error", "?" + e.getMessage()); } finally { IOUtils.closeQuietly(ruInput); } return modelAndView; }
From source file:uk.urchinly.wabi.ingest.UploadController.java
@RequestMapping(method = RequestMethod.POST, value = "/upload") public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) { if (file.isEmpty()) { logger.debug("Upload file is empty."); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with empty file"); }/* w ww. j a v a 2 s . c o m*/ BufferedOutputStream outputStream = null; try { File outputFile = new File(appSharePath + "/" + file.getOriginalFilename()); outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); FileCopyUtils.copy(file.getInputStream(), outputStream); Asset asset = new Asset(file.getOriginalFilename(), file.getOriginalFilename(), (double) file.getSize(), file.getContentType(), Collections.emptyList()); this.saveAsset(asset); } catch (Exception e) { logger.warn(e.getMessage(), e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Failed with error"); } finally { IOUtils.closeQuietly(outputStream); } return ResponseEntity.ok("File accepted"); }
From source file:com.fh.controller.upload.FileUploadController.java
/** * /*w w w . ja v a 2 s. c o m*/ * * @param request * @param name * @param file * @return */ @RequestMapping(value = "/fileUpload", method = RequestMethod.POST) public ModelAndView handleFormUpload(HttpServletRequest request, @RequestParam("name") String name, @RequestParam("file") MultipartFile file) throws Exception { pd = this.getPageData(); String pictureSaveFilePath = PathUtil.getPicturePath("save", "business/businessLicense"); String pictureVisitFilePath = PathUtil.getPicturePath("visit", "business/businessLicense"); if (!file.isEmpty()) { try { String id = UuidUtil.get32UUID(); this.copyFile(file.getInputStream(), pictureSaveFilePath, id + ".jpg").replaceAll("-", ""); String path = pictureVisitFilePath + id + ".jpg"; pd.put("id", id); pd.put("path", path); pd.put("type", 001); pd.put("picture_id", 100); pd.put("explanation", ""); fileUploadService.saveFile(pd); } catch (IOException e) { logger.error(e.getMessage(), e); } } String pathaddress = PathUtil.PathAddress(); pd.get(pathaddress + "path"); pd.put("path", pathaddress + pd.get("path")); mv.setViewName("uploadfile/success"); mv.addObject("pd", pd); return mv; }
From source file:com.insoul.ti.controller.DemandController.java
@RequestMapping("/update/{demandId}") @Transactional(value = "transactionManager", rollbackFor = Throwable.class) public ModelAndView update(@PathVariable Long demandId, @Valid DemandRequest request, BindingResult result) { Demand demand = demandDAO.get(demandId); MultipartFile image = request.getBusinessPlan(); if (image != null) { String fileType = FileUtil.getFileType(image.getOriginalFilename()); if (StringUtils.isNotBlank(fileType)) { String fileName = new StringBuilder().append(UUID.randomUUID()).append(".").append(fileType) .toString();/* w ww . j a v a 2s .c o m*/ try { String path = CDNUtil.uploadFile(image.getInputStream(), fileName); if (StringUtils.isNotBlank(path)) demand.setBusinessPlan(path); } catch (Exception e) { log.error("UploadFile Error.", e); } } } demand.setProjectName(request.getProjectName()); demand.setStatus(request.getStatus()); demand.setAdvantage(request.getAdvantage()); demand.setContent(request.getContent()); demand.setContactPerson(request.getContactPerson()); demand.setContact(request.getContact()); demand.setBusinessLicense(request.getBusinessLicense()); demandDAO.update(demand); return new ModelAndView("redirect:/demand/detail/" + demandId); }
From source file:nl.surfnet.coin.teams.control.AddMemberController.java
/** * Combines the input of the emails field and the csv file * * @param form {@link InvitationForm}/*from w w w .j a v a 2 s . c o m*/ * @return String with the emails * @throws IOException if the CSV file cannot be read */ private String getAllEmailAddresses(InvitationForm form) throws IOException { StringBuilder sb = new StringBuilder(); MultipartFile csvFile = form.getCsvFile(); String emailString = form.getEmails(); boolean appendEmails = StringUtils.hasText(emailString); if (form.hasCsvFile()) { sb.append(IOUtils.toCharArray(csvFile.getInputStream())); if (appendEmails) { sb.append(','); } } if (appendEmails) { sb.append(emailString); } return sb.toString(); }
From source file:com.insoul.ti.controller.FinanceController.java
@RequestMapping("/update/{financingId}") @Transactional(value = "transactionManager", rollbackFor = Throwable.class) public ModelAndView update(@PathVariable Long financingId, @Valid FinanceRequest request, BindingResult result) {/*from ww w . j a v a 2 s. c o m*/ Financing financing = financingDAO.get(financingId); MultipartFile image = request.getBusinessPlan(); if (image != null) { String fileType = FileUtil.getFileType(image.getOriginalFilename()); if (StringUtils.isNotBlank(fileType)) { String fileName = new StringBuilder().append(UUID.randomUUID()).append(".").append(fileType) .toString(); try { String path = CDNUtil.uploadFile(image.getInputStream(), fileName); if (StringUtils.isNotBlank(path)) financing.setBusinessPlan(path); } catch (Exception e) { log.error("UploadFile Error.", e); } } } financing.setProjectName(request.getProjectName()); financing.setStatus(request.getStatus()); financing.setAdvantage(request.getAdvantage()); financing.setContent(request.getContent()); financing.setContactPerson(request.getContactPerson()); financing.setContact(request.getContact()); financing.setBusinessLicense(request.getBusinessLicense()); financingDAO.update(financing); return new ModelAndView("redirect:/finance/detail/" + financingId); }
From source file:org.magnum.dataup.VideoCrt.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id, @RequestParam(value = "data") MultipartFile videoData, HttpServletResponse response) throws IOException { VideoFileManager vfm = VideoFileManager.get(); try {/* ww w . j a v a 2 s.co m*/ if (!videos.containsKey(id)) response.setStatus(HttpServletResponse.SC_NOT_FOUND); else { Video v = videos.get(id); //response.addHeader("Content-Type", v.getContentType ()); vfm.saveVideoData(v, videoData.getInputStream()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } VideoStatus state = new VideoStatus(VideoState.READY); return state; }