List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:com.wavemaker.StudioInstallService.java
public FileUploadResponse uploadPackage(MultipartFile file) throws Exception { File webapproot = new File(RuntimeAccess.getInstance().getSession().getServletContext().getRealPath("")); FileOutputStream fos = null;//www .jav a2s. com // Create our return object FileUploadResponse ret = new FileUploadResponse(); try { /* Find our upload directory, make sure it exists */ File outputFile = new File(webapproot, "repo.zip"); if (outputFile.exists()) outputFile.delete(); /* Write the file to the filesystem */ fos = new FileOutputStream(outputFile); IOUtils.copy(file.getInputStream(), fos); if (!outputFile.exists()) throw new IOException("Insufficient permissions to copy"); File zipFolder = unzipFile(outputFile); //if (!moveFiles(zipFolder, outputFile)) // throw new IOException("Insufficient permissions to copy"); moveFiles(zipFolder, outputFile); /* Setup the return object */ ret.setPath(outputFile.getPath()); ret.setError(""); ret.setWidth(""); ret.setHeight(""); } catch (Exception e) { System.out.println("ERROR:" + e.getMessage() + " | " + e.toString()); ret.setError(e.getMessage()); } finally { file.getInputStream().close(); fos.close(); } return ret; }
From source file:pt.ist.applications.admissions.ui.ApplicationsAdmissionsController.java
@RequestMapping(value = "/candidate/{candidate}/upload", method = RequestMethod.POST) public String candidateUpload(@PathVariable Candidate candidate, @RequestParam String hash, @RequestParam MultipartFile file, @RequestParam String name, final Model model) { if (candidate.verifyHashForEdit(hash)) { try {// w w w .j a va2 s. c o m final String contentType = file.getContentType(); final String filename = chooseFileName(name, file.getOriginalFilename(), contentType); ClientFactory.configurationDriveClient().upload(candidate.getDirectoryForCandidateDocuments(), filename, file.getInputStream(), contentType); } catch (final IOException e) { throw new Error(e); } } return "redirect:/admissions/candidate/" + candidate.getExternalId() + "?hash=" + hash; }
From source file:com.dlshouwen.tdjs.content.controller.TdjsArticleController.java
/** * /* w w w .ja v a 2 s .com*/ * * @param album * @param bindingResult * @return ajax? * @throws Exception */ @RequestMapping(value = "/editAlbum", method = RequestMethod.POST) public void editArtAlbum(@Valid Album album, HttpServletRequest request, BindingResult bindingResult, HttpServletResponse response) throws Exception { // AJAX? AjaxResponse ajaxResponse = new AjaxResponse(); // ?? if (bindingResult.hasErrors()) { ajaxResponse.bindingResultHandler(bindingResult); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "id" + album.getAlbum_id() + "??" + album.getAlbum_name() + "?" + AjaxResponse.getBindingResultMessage(bindingResult) + ""); response.setContentType("text/html;charset=utf-8"); JSONObject obj = JSONObject.fromObject(ajaxResponse); response.getWriter().write(obj.toString()); return; } String path = ""; MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("picture"); String orgFileName = multipartFile.getOriginalFilename(); if (multipartFile != null && StringUtils.isNotEmpty(orgFileName)) { JSONObject jobj = FileUploadClient.upFile(request, orgFileName, multipartFile.getInputStream()); if (jobj != null && jobj.getString("responseMessage").equals("OK")) { path = jobj.getString("fpath"); } } album.setAlbum_coverpath(path); // ???? Date nowDate = new Date(); // ? album.setAlbum_updatedate(nowDate); album.setAlbum_flag("1"); // albumDao.updateAlbum(album); // ???? ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); //URL?? Map map = new HashMap(); map.put("URL", "tdjs/tdjsArticle/article"); ajaxResponse.setExtParam(map); // ? LogUtils.updateOperationLog(request, OperationType.UPDATE, "id" + album.getAlbum_id() + "??" + album.getAlbum_name()); response.setContentType("text/html;charset=utf-8"); JSONObject obj = JSONObject.fromObject(ajaxResponse); response.getWriter().write(obj.toString()); }
From source file:de.hska.ld.content.service.impl.DocumentServiceImpl.java
@Override public Long addAttachment(Long documentId, MultipartFile file, String fileName) { try {//from ww w . j av a 2s . c om return addAttachment(documentId, file.getInputStream(), fileName, file.getSize()); } catch (IOException e) { throw new ValidationException("file"); } }
From source file:com.dlshouwen.tdjs.picture.controller.TdjsPictureController.java
/** * /*from w ww . j a va2 s .c om*/ * * @param picture * @param bindingResult ? * @param request * @return ajax? * @throws Exception */ @RequestMapping(value = "/ajaxEdit", method = RequestMethod.POST) @ResponseBody public void ajaxEditPicture(@Valid Picture picture, HttpServletRequest request, BindingResult bindingResult, HttpServletResponse response) throws Exception { // AJAX? AjaxResponse ajaxResponse = new AjaxResponse(); // ?? if (bindingResult.hasErrors()) { ajaxResponse.bindingResultHandler(bindingResult); // ? LogUtils.updateOperationLog(request, OperationType.INSERT, "???" + AjaxResponse.getBindingResultMessage(bindingResult) + ""); response.setContentType("text/html;charset=utf-8"); JSONObject obj = JSONObject.fromObject(ajaxResponse); response.getWriter().write(obj.toString()); return; } String path = null; MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("picture"); String orgFilename = multipartFile.getOriginalFilename(); if (multipartFile != null && StringUtils.isNotEmpty(orgFilename)) { JSONObject jobj = FileUploadClient.upFile(request, orgFilename, multipartFile.getInputStream()); if (jobj != null && jobj.getString("responseMessage").equals("OK")) { path = jobj.getString("fpath"); } } Picture oldPicture = dao.getPictureById(picture.getPicture_id()); oldPicture.setPicture_name(picture.getPicture_name()); oldPicture.setDescription(picture.getDescription()); oldPicture.setFlag(picture.getFlag()); oldPicture.setShow(picture.getShow()); oldPicture.setTeam_id(picture.getTeam_id()); if (StringUtils.isNotEmpty(path)) { oldPicture.setPath(path); } // ?? Date nowDate = new Date(); // oldPicture.setUpdate_time(nowDate); // dao.updatePicture(oldPicture); // ???? ajaxResponse.setSuccess(true); ajaxResponse.setSuccessMessage("??"); //? Map map = new HashMap(); map.put("URL", "tdjs/tdjsPicture/picture"); ajaxResponse.setExtParam(map); // ? LogUtils.updateOperationLog(request, OperationType.INSERT, "?" + picture.getPicture_id()); response.setContentType("text/html;charset=utf-8"); JSONObject obj = JSONObject.fromObject(ajaxResponse); response.getWriter().write(obj.toString()); }
From source file:org.magnum.dataup.VideoController.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable(VideoSvcApi.ID_PARAMETER) long id, @RequestParam(VideoSvcApi.DATA_PARAMETER) MultipartFile videoData, HttpServletResponse response) throws IOException { System.out.println("Saving video rawData: " + Long.toString(id)); if (!videos.containsKey(id)) { System.out.println("Id for video not found"); response.setStatus(HttpStatus.NOT_FOUND.value()); } else if (id > 0) { System.out.println("Start saving video rawData: " + videos.get(id)); Video v = videos.get(id);/*from w w w .j av a 2 s .com*/ if (videoDataMgr == null) { videoDataMgr = VideoFileManager.get(); } videoDataMgr.saveVideoData(v, videoData.getInputStream()); System.out.println("Video raw data was saved at id: " + v); } return new VideoStatus(VideoState.READY); }
From source file:net.duckling.ddl.web.controller.team.ConfigTeamController.java
@RequestMapping(method = RequestMethod.POST, params = "func=uploadMailList") public void uploadMailList(@RequestParam("qqfile") MultipartFile uplFile, HttpServletResponse response) throws IOException { InputStream in = uplFile.getInputStream(); String fileName = uplFile.getOriginalFilename(); uploadMailListCommon(fileName, in, response); }
From source file:de.hska.ld.content.service.impl.DocumentServiceImpl.java
@Override public Long updateAttachment(Long documentId, Long attachmentId, MultipartFile file, String fileName) { try {//from w w w . j a v a 2s . c o m return updateAttachment(documentId, attachmentId, file.getInputStream(), fileName); } catch (IOException e) { throw new ValidationException("file"); } }
From source file:com.courtalon.gigaMvcGalerie.web.ImageController.java
@RequestMapping(value = "/images/data", method = RequestMethod.POST, produces = "application/json") @ResponseBody//from w ww .j a v a 2s .co m @JsonView(AssetOnly.class) public Image upload(@RequestParam("file") MultipartFile file, @RequestParam("licenseId") Optional<Integer> licenseId, @RequestParam("sourceId") Optional<Integer> sourceId, @RequestParam("tagsId") Optional<List<Integer>> tagsId) { Image img = null; try { img = getImageRepository() .save(new Image(0, file.getOriginalFilename(), "", new Date(), file.getOriginalFilename(), file.getContentType(), file.getSize(), DigestUtils.md5Hex(file.getInputStream()))); getImageRepository().saveImageFile(img.getId(), file.getInputStream()); img.addTag(getTagRepository().findByLibelleAndSystemTag(TagRepository.UPLOADED, true)); img.setLicense(getLicenseTypeRepository().findOne(licenseId.orElse(LicenseType.NO_LICENSE_ID))); img.setSource(getAssetSourceRepository().findOne(sourceId.orElse(AssetSource.UNKOWN_SOURCE_ID))); final Image image = img; if (tagsId.isPresent()) { tagsId.get().forEach(id -> image.addTag(getTagRepository().findByIdAndSystemTag(id, false))); } getImageRepository().save(img); } catch (IOException e) { log.error(e); throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "could not save uploaded image"); } return img; }
From source file:eu.freme.broker.eservices.EPublishing.java
@RequestMapping(value = "/e-publishing/html", method = RequestMethod.POST) public ResponseEntity<byte[]> htmlToEPub(@RequestParam("htmlZip") MultipartFile file, @RequestParam("metadata") String jMetadata) throws InvalidZipException, EPubCreationException, IOException, MissingMetadataException { if (file.getSize() > maxUploadSize) { double size = maxUploadSize / (1024.0 * 1024); return new ResponseEntity<>(new byte[0], HttpStatus.BAD_REQUEST); //throw new BadRequestException(String.format("The uploaded file is too large. The maximum file size for uploads is %.2f MB", size)); }//from ww w. j a v a2 s . c o m Gson gson = new Gson(); Metadata metadata = gson.fromJson(jMetadata, Metadata.class); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/epub+zip"); try { return new ResponseEntity<>(entityAPI.createEPUB(metadata, file.getInputStream()), HttpStatus.OK); } catch (InvalidZipException | EPubCreationException | IOException | MissingMetadataException ex) { logger.log(Level.SEVERE, ex.getMessage()); throw ex; } }