List of usage examples for org.springframework.web.multipart MultipartFile getSize
long getSize();
From source file:com.sliu.framework.app.process.controller.ProcessXNController.java
/** * ?,??????API// w w w.ja v a2 s. c o m */ @RequestMapping(value = "/deployProcess", method = RequestMethod.POST) @ResponseBody public String deployProcess(@RequestParam("attachMentFile") MultipartFile multipartFile) throws FileNotFoundException { if (multipartFile != null && multipartFile.getSize() != 0) { //,??? FileCommonOperate fileCommonOperate = new FileCommonOperate(); try { String fileName = fileCommonOperate.uploadFile(multipartFile.getInputStream(), deployFilePath, multipartFile.getOriginalFilename()); InputStream fileInputStream = multipartFile.getInputStream(); String extension = FilenameUtils.getExtension(fileName); if (extension.equals("zip") || extension.equals("bar")) { ZipInputStream zip = new ZipInputStream(fileInputStream); repositoryService.createDeployment().addZipInputStream(zip).deploy(); } else { repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy(); } } catch (IOException e) { e.printStackTrace(); } } return "{success:true}"; }
From source file:com.intranet.intr.inbox.SupControllerInbox.java
@RequestMapping(method = RequestMethod.POST) public @ResponseBody String doUpload(@RequestParam("file") MultipartFile multipartFile) { return "Uploaded: " + multipartFile.getSize() + " bytes"; }
From source file:com.devnexus.ting.web.controller.admin.OrganizerController.java
@RequestMapping(value = "/s/admin/organizer", method = RequestMethod.POST) public String addOrganizer(@RequestParam MultipartFile pictureFile, @Valid Organizer organizerForm, BindingResult result, HttpServletRequest request, RedirectAttributes redirectAttributes) { if (request.getParameter("cancel") != null) { return "redirect:/s/admin/organizers"; }/*from www .jav a 2 s . c om*/ if (result.hasErrors()) { return "/admin/add-organizer"; } if (pictureFile != null && pictureFile.getSize() > 0) { final FileData pictureData = new FileData(); try { pictureData.setFileData(IOUtils.toByteArray(pictureFile.getInputStream())); pictureData.setFileSize(pictureFile.getSize()); pictureData.setFileModified(new Date()); pictureData.setName(pictureFile.getOriginalFilename()); } catch (IOException e) { throw new IllegalStateException( "Error while processing image for speaker " + organizerForm.getFirstLastName(), e); } organizerForm.setPicture(pictureData); String message = "File '" + organizerForm.getPicture().getName() + "' uploaded successfully"; redirectAttributes.addFlashAttribute("successMessage", message); } Organizer savedOrganizer = businessService.saveOrganizer(organizerForm); redirectAttributes.addFlashAttribute("successMessage", String.format("The organizer '%s' was added successfully.", savedOrganizer.getFirstLastName())); return "redirect:/s/admin/organizers"; }
From source file:cherry.foundation.async.AsyncFileProcessHandlerImplTest.java
@Test public void testLaunchFileProcess_IOException() throws Exception { AsyncFileProcessHandlerImpl impl = createImpl(); LocalDateTime now = LocalDateTime.now(); when(bizDateTime.now()).thenReturn(now); when(asyncProcessStore.createFileProcess("a", now, "b", "c", "d", "e", 100L, "f")).thenReturn(10L); IOException ioException = new IOException(); MultipartFile file = mock(MultipartFile.class); when(file.getName()).thenReturn("c"); when(file.getOriginalFilename()).thenReturn("d"); when(file.getContentType()).thenReturn("e"); when(file.getSize()).thenReturn(100L); when(file.getInputStream()).thenThrow(ioException); try {// w w w.jav a 2 s . c o m impl.launchFileProcess("a", "b", file, "f"); fail("Exception must be thrown"); } catch (IllegalStateException ex) { assertEquals(ioException, ex.getCause()); } }
From source file:cherry.foundation.async.AsyncFileProcessHandlerImplTest.java
@Test public void testLaunchFileProcess_exception() throws Exception { AsyncFileProcessHandlerImpl impl = createImpl(); LocalDateTime now = LocalDateTime.now(); when(bizDateTime.now()).thenReturn(now); when(asyncProcessStore.createFileProcess("a", now, "b", "c", "d", "e", 100L, "f")).thenReturn(10L); IOException exception = new IOException(); InputStream in = mock(InputStream.class); when(in.read((byte[]) any())).thenThrow(exception); MultipartFile file = mock(MultipartFile.class); when(file.getName()).thenReturn("c"); when(file.getOriginalFilename()).thenReturn("d"); when(file.getContentType()).thenReturn("e"); when(file.getSize()).thenReturn(100L); when(file.getInputStream()).thenReturn(in); try {//from w ww .j a v a 2s . co m impl.launchFileProcess("a", "b", file, "f"); fail("Exception must be thrown"); } catch (IllegalStateException ex) { verify(asyncProcessStore).createFileProcess("a", now, "b", "c", "d", "e", 100L, "f"); verify(asyncProcessStore).finishWithException(10L, now, exception); } }
From source file:cherry.foundation.async.AsyncFileProcessHandlerImplTest.java
@Test public void testLaunchFileProcess_NO_ARG() throws Exception { AsyncFileProcessHandlerImpl impl = createImpl(); LocalDateTime now = LocalDateTime.now(); when(bizDateTime.now()).thenReturn(now); when(asyncProcessStore.createFileProcess("a", now, "b", "c", "d", "e", 100L, "f")).thenReturn(10L); MultipartFile file = mock(MultipartFile.class); when(file.getName()).thenReturn("c"); when(file.getOriginalFilename()).thenReturn("d"); when(file.getContentType()).thenReturn("e"); when(file.getSize()).thenReturn(100L); when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[0])); @SuppressWarnings("rawtypes") ArgumentCaptor<Map> message = ArgumentCaptor.forClass(Map.class); long asyncId = impl.launchFileProcess("a", "b", file, "f"); assertEquals(10L, asyncId);//from w w w . j a va 2s . c o m verify(jmsOperations).convertAndSend(message.capture(), eq(messagePostProcessor)); assertEquals("10", message.getValue().get("asyncId")); String fileName = (String) message.getValue().get("file"); assertTrue(fileName.startsWith((new File(tempDir, "prefix_")).getAbsolutePath())); assertTrue(fileName.endsWith(".csv")); assertEquals("c", message.getValue().get("name")); assertEquals("d", message.getValue().get("originalFilename")); assertEquals("e", message.getValue().get("contentType")); assertEquals("100", message.getValue().get("size")); assertEquals("f", message.getValue().get("handlerName")); verify(asyncProcessStore).createFileProcess("a", now, "b", "c", "d", "e", 100L, "f"); verify(asyncProcessStore).updateToLaunched(10L, now); }
From source file:org.ktunaxa.referral.server.mvc.UploadDocumentController.java
@RequestMapping(value = "/upload/referral/document", method = RequestMethod.POST) public String handleFormUpload(@RequestParam(KtunaxaConstant.FORM_ID) String formId, @RequestParam(KtunaxaConstant.FORM_REFERRAL) String referralId, @RequestParam(value = KtunaxaConstant.FORM_OVERRIDE, required = false) String override, @RequestParam("file") MultipartFile file, Model model) { UploadResponse response = new UploadResponse(); response.addObject(KtunaxaConstant.FORM_ID, formId); try {/*from ww w . j a v a2 s .c o m*/ String year = "20" + referralId.substring(8, 10); String originalFilename = file.getOriginalFilename(); Document document; if (override != null && "true".equalsIgnoreCase(override)) { document = cmisService.saveOrUpdate(originalFilename, file.getContentType(), file.getInputStream(), file.getSize(), year, referralId); } else { document = cmisService.create(originalFilename, file.getContentType(), file.getInputStream(), file.getSize(), year, referralId); } response.addObject(KtunaxaConstant.FORM_DOCUMENT_TITLE, originalFilename); response.addObject(KtunaxaConstant.FORM_DOCUMENT_ID, document.getId()); response.addObject(KtunaxaConstant.FORM_DOCUMENT_DISPLAY_URL, cmisService.getDisplayUrl(document)); response.addObject(KtunaxaConstant.FORM_DOCUMENT_DOWNLOAD_URL, cmisService.getDownloadUrl(document)); model.addAttribute(UploadView.RESPONSE, response); } catch (Exception e) { log.error("Could not upload document", e); response.setException(e); } model.addAttribute(UploadView.RESPONSE, response); return UploadView.NAME; }
From source file:cherry.foundation.async.AsyncFileProcessHandlerImplTest.java
@Test public void testLaunchFileProcess_2_ARGS() throws Exception { AsyncFileProcessHandlerImpl impl = createImpl(); LocalDateTime now = LocalDateTime.now(); when(bizDateTime.now()).thenReturn(now); when(asyncProcessStore.createFileProcess("a", now, "b", "c", "d", "e", 100L, "f", "g", "h")) .thenReturn(10L);//from ww w. j a v a 2s . co m MultipartFile file = mock(MultipartFile.class); when(file.getName()).thenReturn("c"); when(file.getOriginalFilename()).thenReturn("d"); when(file.getContentType()).thenReturn("e"); when(file.getSize()).thenReturn(100L); when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[0])); @SuppressWarnings("rawtypes") ArgumentCaptor<Map> message = ArgumentCaptor.forClass(Map.class); long asyncId = impl.launchFileProcess("a", "b", file, "f", "g", "h"); assertEquals(10L, asyncId); verify(jmsOperations).convertAndSend(message.capture(), eq(messagePostProcessor)); assertEquals("10", message.getValue().get("asyncId")); String fileName = (String) message.getValue().get("file"); assertTrue(fileName.startsWith((new File(tempDir, "prefix_")).getAbsolutePath())); assertTrue(fileName.endsWith(".csv")); assertEquals("c", message.getValue().get("name")); assertEquals("d", message.getValue().get("originalFilename")); assertEquals("e", message.getValue().get("contentType")); assertEquals("100", message.getValue().get("size")); assertEquals("f", message.getValue().get("handlerName")); assertEquals("g", message.getValue().get("0")); assertEquals("h", message.getValue().get("1")); verify(asyncProcessStore).createFileProcess("a", now, "b", "c", "d", "e", 100L, "f", "g", "h"); verify(asyncProcessStore).updateToLaunched(10L, now); }
From source file:de.blizzy.documentr.web.attachment.AttachmentController.java
@RequestMapping(value = "/saveViaJson/{projectName:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}/" + "{branchName:" + DocumentrConstants.BRANCH_NAME_PATTERN + "}/" + "{pagePath:" + DocumentrConstants.PAGE_PATH_URL_PATTERN + "}/json", method = RequestMethod.POST) @PreAuthorize("hasPagePermission(#projectName, #branchName, #pagePath, EDIT_PAGE)") @ResponseBody//from www .j a va 2s. co m public Map<String, Object> saveAttachmentViaJson(@PathVariable String projectName, @PathVariable String branchName, @PathVariable String pagePath, @RequestParam MultipartFile file, Authentication authentication) throws IOException { log.info("saving attachment via JSON: {}", file.getOriginalFilename()); //$NON-NLS-1$ saveAttachmentInternal(projectName, branchName, pagePath, file, authentication); Map<String, Object> fileResult = Maps.newHashMap(); fileResult.put("name", file.getOriginalFilename()); //$NON-NLS-1$ fileResult.put("size", file.getSize()); //$NON-NLS-1$ fileResult.put("url", StringUtils.EMPTY); //$NON-NLS-1$ fileResult.put("thumbnail_url", StringUtils.EMPTY); //$NON-NLS-1$ fileResult.put("delete_url", StringUtils.EMPTY); //$NON-NLS-1$ fileResult.put("delete_type", StringUtils.EMPTY); //$NON-NLS-1$ List<Map<String, Object>> filesList = Lists.newArrayList(); filesList.add(fileResult); Map<String, Object> result = Maps.newHashMap(); result.put("files", filesList); //$NON-NLS-1$ return result; }
From source file:com.climate.oada.controller.OADAAPIController.java
@Override public Map<String, String> uploadFile( @RequestHeader(value = "Authorization", required = true) String accessToken, @RequestParam("file") MultipartFile file) { Map<String, String> retval = new HashMap<String, String>(); try {/*w w w. j ava 2 s. c o m*/ boolean uploadStatus = getS3DAO().saveFile(file); if (uploadStatus) { retval.put("Uploaded file name", file.getOriginalFilename()); retval.put("fileSize", new Long(file.getSize()).toString()); } } catch (Exception e) { retval.put("Upload failed, reason", e.getMessage()); } return retval; }