List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:com.epam.ta.reportportal.core.user.impl.EditUserHandler.java
@Override public OperationCompletionRS uploadPhoto(String username, MultipartFile file) { try {/* www. j a v a2s .c om*/ validatePhoto(file); BinaryData binaryData = new BinaryData(file.getContentType(), file.getSize(), file.getInputStream()); userRepository.replaceUserPhoto(username, binaryData); } catch (IOException e) { fail().withError(BINARY_DATA_CANNOT_BE_SAVED); } return new OperationCompletionRS("Profile photo has been uploaded successfully"); }
From source file:io.lavagna.web.api.CardDataControllerTest.java
@Test public void uploadFiles() throws NoSuchAlgorithmException, IOException { MultipartFile f = mock(MultipartFile.class); when(f.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[] { 42, 42, 42, 42, 84, 84, 84 })); when(cardDataService.createFile(any(String.class), any(String.class), any(Integer.class), any(Integer.class), any(InputStream.class), any(String.class), any(User.class), any(Date.class))) .thenReturn(ImmutablePair.of(true, mock(CardData.class))); List<MultipartFile> files = Arrays.asList(f); cardDataController.uploadFiles(cardId, files, user, new MockHttpServletResponse()); }
From source file:org.magnum.dataup.VideoSvcCtrl.java
/** * Save some or part of a videos data when * we're initially uploading it from MultipartFile data * @throws IOException /* w ww .j ava2 s . c om*/ */ public void saveSomeData(Video video, MultipartFile videoData) throws IOException { mVideoFileManager = VideoFileManager.get(); mVideoFileManager.saveVideoData(video, videoData.getInputStream()); }
From source file:ch.ledcom.jpreseed.web.TemporaryPreseedStore.java
public void addPreseeds(Collection<MultipartFile> preseeds) throws IOException { for (MultipartFile multipartFile : preseeds) { String name = multipartFile.getName(); logger.debug("Adding pressed [{}] to preseed store.", name); Path preseed = tempDir.resolve(name); preseedPaths.add(preseed);//from w ww.j a v a 2 s . co m try (InputStream in = multipartFile.getInputStream()) { Files.copy(in, preseed, REPLACE_EXISTING); } } }
From source file:com.orange.clara.cloud.poc.s3.controller.PocS3Controller.java
@RequestMapping(value = "/uploadInStream", method = RequestMethod.POST) public String uploadInStream(@RequestParam("name") String name, @RequestParam("file") MultipartFile multipartFile, Model model) throws IOException { if (multipartFile.isEmpty()) { return "You failed to upload " + name + " because the file was empty."; }/*from w ww.j a va2 s . co m*/ InputStream multipartFileStream = multipartFile.getInputStream(); Blob blob = this.blobStore.blobBuilder(name).build(); this.uploadS3Stream.upload(multipartFileStream, blob); model.addAttribute("message", "We uploaded the file '" + name + "' to a riakcs"); return "success"; }
From source file:de.whs.poodle.controllers.ImageController.java
@RequestMapping(value = "/instructor/images/{courseId}", method = RequestMethod.POST) @ResponseBody // send the response directly to the client instead of rendering an HTML page public String uploadImage(@ModelAttribute Instructor instructor, @PathVariable int courseId, @RequestParam int CKEditorFuncNum, MultipartHttpServletRequest request) throws IOException { InputStream in = null;//w w w . j a v a 2 s . c o m try { String filename = request.getFileNames().next(); MultipartFile multipartFile = request.getFile(filename); String originalFilename = multipartFile.getOriginalFilename(); String mimetype = multipartFile.getContentType(); in = multipartFile.getInputStream(); long length = multipartFile.getSize(); UploadedImage image = new UploadedImage(); image.setCourseId(courseId); image.setInstructor(instructor); image.setFilename(originalFilename); image.setMimeType(mimetype); imageRepo.uploadImage(image, in, length); String path = request.getContextPath() + "/images/" + image.getId(); return generateResponse(CKEditorFuncNum, path, null); } catch (Exception e) { log.error("Error uploading image", e); return generateResponse(CKEditorFuncNum, null, "Fehler beim Upload"); } finally { if (in != null) in.close(); } }
From source file:com.rajaram.bookmark.controller.BookmarkController.java
/** * <P>//from w w w. j av a2 s. c om * Upload single bookmark file. * </P> * * @param userName * @param file * @return */ @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) @ApiOperation(httpMethod = "POST", value = "Upload and extract data " + "from the bookmark file and stores the extracted data to the" + " bookmark SQL table.", produces = ("application/json,application/xml")) public @ResponseBody Response uploadFileHandler( @ApiParam(name = "userName", value = "user name", required = true) @RequestParam String userName, @ApiParam(name = "file", value = "file", required = true) @RequestParam MultipartFile file) { userName = URLDecoder.decode(userName); Response response = new Response(); InputStream fileIn = null; try { fileIn = file.getInputStream(); } catch (IOException ex) { Logger.getLogger(BookmarkController.class.getName()).log(Level.SEVERE, null, ex); response.setMessage("Error reading bookmark file. Error message : " + ex.getMessage()); return response; } List<Bookmark> bookmarks = bookmarkOperation.extractNetscapeBookmarks(fileIn); try { bookmarkService.insertBookmarks(userName, bookmarks); response.setMessage("Bookmark data is stored in the database"); } catch (DataAccessException ex) { response.setMessage("Error storing bookmark data. Error message : " + ex.getMessage()); } return response; }
From source file:org.openmrs.module.dhisreport.web.controller.ReportDefinitionController.java
@RequestMapping(value = "/module/dhisreport/loadReportDefinitions", method = RequestMethod.POST) public void upload(ModelMap model, HttpServletRequest request) throws Exception { HttpSession session = request.getSession(); model.addAttribute("user", Context.getAuthenticatedUser()); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("datafile"); DHIS2ReportingService service = Context.getService(DHIS2ReportingService.class); InputStream is = multipartFile.getInputStream(); try {//from www. jav a 2s . c om service.unMarshallandSaveReportTemplates(is); session.setAttribute(WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("dhisreport.uploadSuccess")); } catch (Exception ex) { log.error("Error loading file: " + ex); session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("dhisreport.uploadError")); } finally { is.close(); } }
From source file:org.magnum.dataup.VideoServiceController.java
@RequestMapping(value = DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id, @RequestParam("data") MultipartFile videoData, HttpServletResponse response) throws IOException { VideoStatus result = null;/*w w w . j a va 2s. c o m*/ if (videos.containsKey(id)) { if (videoData != null) { manager.saveVideoData(videos.get(id), videoData.getInputStream()); result = new VideoStatus(VideoState.READY); } else { response.sendError(400, "No video data given."); } } else { response.sendError(404, "No video with id=" + id + " exists."); } return result; }
From source file:org.jtalks.common.web.validation.ImageDimensionValidator.java
/** * Validate object with {@link ImageDimension} annotation. * * @param multipartFile image that user want upload as avatar * @param context validation context * @return {@code true} if validation successfull or false if fails *///from w ww . j a v a 2 s . c o m @Override public boolean isValid(MultipartFile multipartFile, ConstraintValidatorContext context) { if (multipartFile.isEmpty()) { //assume that empty multipart file is valid to avoid validation message when user doesn't load nothing return true; } Image image; try { image = ImageIO.read(multipartFile.getInputStream()); } catch (Exception e) { return false; } return (image == null) ? false : image.getWidth(null) == imageWidth && image.getHeight(null) == imageHeight; }