List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename
@Nullable String getOriginalFilename();
From source file:com.abixen.platform.service.businessintelligence.multivisualisation.service.impl.DataFileServiceImpl.java
@Override public FileParserMessage<DataFileColumn> uploadAndParseFile(MultipartFile multipartFile, Boolean readFirstColumnAsColumnName) { String fileName = multipartFile.getOriginalFilename(); FileParserService fileParserService = fileParserFactory .getParse(fileName.substring(fileName.lastIndexOf("."))); return fileParserService.parseFile(multipartFile, readFirstColumnAsColumnName); }
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 w w w .j a va2 s . co 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:com.zuoxiaolong.niubi.job.console.controller.MasterSlaveJobController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) @ExceptionForward("/masterSlaveJobSummaries") public String upload(String packagesToScan, @RequestParam MultipartFile jobJar) { AssertHelper.notNull(jobJar, "jobJar can't be null."); AssertHelper.notEmpty(packagesToScan, "packagesToScan can't be empty."); String jarFilePath = getDirectoryRealPath("job/masterSlave") + "/" + jobJar.getOriginalFilename(); try {//from w w w .j a va 2s. c o m IOHelper.writeFile(jarFilePath, jobJar.getBytes()); masterSlaveJobService.saveJob(jarFilePath, packagesToScan); } catch (IOException e) { throw new NiubiException(e); } return "forward:/masterSlaveJobSummaries"; }
From source file:org.bonitasoft.web.designer.controller.ImportController.java
private boolean isNotZipFile(MultipartFile file) { return !MimeType.APPLICATION_ZIP.matches(file.getContentType()) && !(MimeType.APPLICATION_OCTETSTREAM.matches(file.getContentType()) && file.getOriginalFilename().endsWith(".zip")); }
From source file:org.jasig.portlet.blackboardvcportlet.mvc.sessionmngr.ManageMediaFilesController.java
@ActionMapping("uploadMediaFile") public void uploadMultimedia(ActionResponse response, Locale locale, @RequestParam long sessionId, @RequestParam MultipartFile multimediaUpload) throws PortletModeException { final String fileExtension = FilenameUtils.getExtension(multimediaUpload.getOriginalFilename()); // Validate/*from ww w . j av a 2s . c o m*/ if (multimediaUpload.getSize() < 1) { response.setRenderParameter("multimediaUploadError", messageSource.getMessage("error.uploadfilenotselected", null, locale)); } else if (multimediaUpload.getSize() > maxFileUploadSize) { response.setRenderParameter("multimediaUploadError", messageSource .getMessage("error.uploadfilesizetoobig", new Object[] { maxFileUploadSize }, locale)); } else if (fileExtension.length() == 0 || !multimediaFileTypes.contains(fileExtension.toLowerCase())) { response.setRenderParameter("multimediaUploadError", messageSource.getMessage("error.uploadfileextensionswrong", null, locale)); } else { this.sessionService.addMultimedia(sessionId, multimediaUpload); } response.setPortletMode(PortletMode.EDIT); response.setRenderParameter("sessionId", Long.toString(sessionId)); response.setRenderParameter("action", "manageMediaFiles"); }
From source file:it.cilea.osd.jdyna.controller.AFormEditTabController.java
/** * /*from w w w.j a v a2 s.co m*/ * Load tab icon and copy to default directory. * * @param researcher * @param rp * @param itemImage * MultipartFile to use in webform * @throws IOException * @throws FileNotFoundException */ public void loadTabIcon(ET tab, String iconName, MultipartFile itemImage) throws IOException, FileNotFoundException { String pathImage = tab.getFileSystemPath(); String ext = itemImage.getOriginalFilename() .substring(itemImage.getOriginalFilename().lastIndexOf(".") + 1); File dir = new File(pathImage + File.separatorChar + DIRECTORY_TAB_ICON); dir.mkdir(); File file = new File(dir, PREFIX_TAB_ICON + iconName + "." + ext); file.createNewFile(); FileOutputStream out = new FileOutputStream(file); it.cilea.osd.common.util.Utils.bufferedCopy(itemImage.getInputStream(), out); out.close(); tab.setExt(ext); tab.setMime(itemImage.getContentType()); }
From source file:it.cilea.osd.jdyna.controller.AFormTabController.java
/** * /*from w w w. ja v a2 s. c o m*/ * Load tab icon and copy to default directory. * * @param researcher * @param rp * @param itemImage * MultipartFile to use in webform * @throws IOException * @throws FileNotFoundException */ public void loadTabIcon(T tab, String iconName, MultipartFile itemImage) throws IOException, FileNotFoundException { String pathImage = tab.getFileSystemPath(); String ext = itemImage.getOriginalFilename() .substring(itemImage.getOriginalFilename().lastIndexOf(".") + 1); File dir = new File(pathImage + File.separatorChar + DIRECTORY_TAB_ICON); dir.mkdir(); File file = new File(dir, PREFIX_TAB_ICON + iconName + "." + ext); file.createNewFile(); FileOutputStream out = new FileOutputStream(file); it.cilea.osd.common.util.Utils.bufferedCopy(itemImage.getInputStream(), out); out.close(); tab.setExt(ext); tab.setMime(itemImage.getContentType()); }
From source file:com.mmj.app.web.controller.upload.FileUploadController.java
@RequestMapping("/doUpload.htm") public ModelAndView fileUpload(@RequestParam("file") MultipartFile file) { Result result = null;//from w ww . j a v a 2 s . c om if (!file.isEmpty()) { result = fileService.createFilePath(file, file.getOriginalFilename()); } if (result == null || result.getData() == null) { return createFileJsonMav(ResultCode.ERROR, "", null); } return createFileJsonMav(ResultCode.SUCCESS, "?", result.getData().toString()); }
From source file:cs544.videohouse.validator.VideoConstraintValidator.java
@Override public boolean isValid(MultipartFile video, ConstraintValidatorContext context) { System.out.println("inside video validation method"); boolean valid = true; if (video.isEmpty()) { valid = false;/*from w ww.j a va 2s . c o m*/ } else { String videoExt = FilenameUtils.getExtension(video.getOriginalFilename()); if (!"mp4".equals(videoExt) && !"ogg".equals(videoExt) && !"ogv".equals(videoExt) && !"webM".equals(videoExt)) { valid = false; } long bytes = video.getSize(); if (bytes > 20000000) { valid = false; } System.out.println("size : " + bytes); } return valid; }
From source file:alpha.portal.webapp.controller.CardFileUploadController.java
/** * handles the case, if the user clicks on one of the buttons. * /*from w ww. j a va 2s. c om*/ * @param fileUpload * the file upload * @param errors * the errors * @param request * the request * @return success view * @throws IOException * Signals that an I/O exception has occurred. */ @RequestMapping(method = RequestMethod.POST) public String onSubmit(final FileUpload fileUpload, final BindingResult errors, final HttpServletRequest request) throws IOException { final String caseId = request.getParameter("case"); final String cardId = request.getParameter("card"); final Locale locale = request.getLocale(); this.setCancelView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); this.setSuccessView("redirect:/caseform?caseId=" + caseId + "&activeCardId=" + cardId); final AlphaCard card = this.alphaCardManager.get(new AlphaCardIdentifier(caseId, cardId)); if (card == null) { this.saveError(request, this.getText("card.invalidId", locale)); return this.getCancelView(); } final Adornment contributor = card.getAlphaCardDescriptor() .getAdornment(AdornmentType.Contributor.getName()); if ((contributor.getValue() == null) || contributor.getValue().isEmpty()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return this.getCancelView(); } else { final Long contributorID = Long.parseLong(contributor.getValue()); final User currentUser = this.getUserManager().getUserByUsername(request.getRemoteUser()); if (contributorID != currentUser.getId()) { this.saveError(request, this.getText("adornment.noAccess", locale)); return this.getCancelView(); } } if (request.getParameter("cancel") != null) return this.getCancelView(); if (this.validator != null) { // validator is null during testing fileUpload.setName("alphaCardPayloadFile"); this.validator.validate(fileUpload, errors); if (errors.hasErrors()) return "redirect:/cardfileupload?card=" + cardId + "&case=" + caseId; } // validate a file was entered if (fileUpload.getFile().length == 0) { final Object[] args = new Object[] { this.getText("uploadForm.file", request.getLocale()) }; errors.rejectValue("file", "errors.required", args, "File"); return "redirect:/cardfileupload?card=" + cardId + "&case=" + caseId; } final MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; final MultipartFile file = multipartRequest.getFile("file"); Payload payload = new Payload(file.getOriginalFilename(), file.getContentType()); payload.setContent(file.getBytes()); payload = this.payloadManager.saveNewPayload(payload, card); this.saveMessage(request, this.getText("card.payloadOK", locale)); return this.getSuccessView(); }