List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename
@Nullable String getOriginalFilename();
From source file:it.geosolutions.operations.FileBrowserOperationController.java
/** * Shows the list of files inside the selected folder after a file upload * @param model/*from w w w .j a v a 2 s . c o m*/ * @return */ //@RequestMapping(value = "/files", method = RequestMethod.POST) public String saveFileAndList(@ModelAttribute("uploadFile") FileUpload uploadFile, ModelMap model) { List<MultipartFile> files = uploadFile.getFiles(); List<String> fileNames = new ArrayList<String>(); if (null != files && files.size() > 0) { for (MultipartFile multipartFile : files) { String fileName = multipartFile.getOriginalFilename(); if (!"".equalsIgnoreCase(fileName)) { //Handle file content - multipartFile.getInputStream() try { multipartFile.transferTo(new File(getDefaultBaseDir() + fileName)); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } fileNames.add(fileName); } System.out.println(fileName); } } model.addAttribute("uploadedFiles", fileNames); FileBrowser fb = new FileBrowser(); fb.setBaseDir(getDefaultBaseDir()); fb.setRegex(null); fb.setScanDiretories(canNavigate); model.addAttribute("fileBrowser", fb); model.addAttribute("operations", getAvailableOperations()); model.addAttribute("context", operationJSP); ControllerUtils.setCommonModel(model); return "template"; }
From source file:org.freeeed.search.files.CaseFileService.java
public String uploadFile(MultipartFile file) { File uploadDir = new File(UPLOAD_DIR); uploadDir.mkdirs();//from w w w.j ava 2s . c o m String destinationFile = UPLOAD_DIR + File.separator + df.format(new Date()) + "-" + file.getOriginalFilename(); File destination = new File(destinationFile); try { file.transferTo(destination); return destinationFile; } catch (Exception e) { log.error("Problem uploading file: ", e); return null; } }
From source file:com.github.zhanhb.ckfinder.connector.handlers.command.FileUploadCommand.java
/** * save if uploaded file item name is full file path not only file name. * * @param item file upload item/*from w w w . ja va2s . c om*/ * @return file name of uploaded item */ private String getFileItemName(MultipartFile item) { Pattern p = Pattern.compile("[^\\\\/]+$"); Matcher m = p.matcher(item.getOriginalFilename()); return m.find() ? m.group() : ""; }
From source file:com.trenako.web.images.ThumbnailatorService.java
@Override public UploadFile createThumbnail(MultipartFile file, Map<String, String> metadata, int targetSize) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Thumbnails.of(inputStream(file)).height(targetSize).outputQuality(0.8d).toOutputStream(baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); baos.close();//from w ww .ja v a2 s. c o m return new UploadFile(is, file.getContentType(), file.getOriginalFilename(), metadata); }
From source file:no.dusken.aranea.admin.control.EditBannerController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException errors) throws Exception { Banner banner = (Banner) object;//from w ww. j a va 2 s.c o m MultipartHttpServletRequest multipart_request = (MultipartHttpServletRequest) request; MultipartFile file = multipart_request.getFile("file"); if (banner.getType().equals(BannerType.Script)) { banner.setHash(MD5.asHex(banner.getScript().getBytes()).substring(0, 100)); } if (file != null && file.getSize() > 0 && banner.getType() != BannerType.Script) { String fileName = file.getOriginalFilename(); File bannerFile = new File(bannerDirectory + "/tmp/" + fileName); bannerFile.mkdirs(); file.transferTo(bannerFile); String hash = MD5.asHex(MD5.getHash(bannerFile)); banner.setHash(hash); FileUtils.copyFile(bannerFile, new File(bannerDirectory + "/" + banner.getHash() + "." + banner.getType().toString())); bannerFile.delete(); } else { errors.reject("A file is required"); } return super.onSubmit(request, response, banner, errors); }
From source file:org.jasig.portlet.blackboardvcportlet.mvc.sessionmngr.SessionCreateEditController.java
@ActionMapping(params = "action=Upload Presentation") public void uploadPresentation(ActionResponse response, Locale locale, @RequestParam long sessionId, @RequestParam MultipartFile presentationUpload, @RequestParam boolean needToSendInitialEmail) throws PortletModeException { String fileExtension = StringUtils.substringAfter(presentationUpload.getOriginalFilename(), ".") .toLowerCase();//from w ww. j a v a2 s .c om // Validate if (presentationUpload.getSize() < 1) { response.setRenderParameter("presentationUploadError", messageSource.getMessage("error.uploadfilenotselected", null, locale)); } else if (presentationUpload.getSize() > maxFileUploadSize) { response.setRenderParameter("presentationUploadError", messageSource.getMessage("error.uploadfilesizetoobig", null, locale)); } else if (fileExtension.length() == 0 || !presentationFileTypes.contains(fileExtension)) { response.setRenderParameter("presentationUploadError", messageSource.getMessage("error.uploadfileextensionswrong", null, locale)); } else { this.sessionService.addPresentation(sessionId, presentationUpload); } response.setPortletMode(PortletMode.VIEW); response.setRenderParameter("sessionId", Long.toString(sessionId)); response.setRenderParameter("action", "viewSession"); response.setRenderParameter("needToSendInitialEmail", Boolean.toString(needToSendInitialEmail)); }
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 . jav 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.mycompany.rent.controllers.ListingController.java
@RequestMapping(value = "/photo/{id}", method = RequestMethod.POST) public String addPhotos(@RequestParam("file") MultipartFile file, @PathVariable int id, Map model) throws IOException { if (!file.isEmpty()) { ForRent rent = forRentDao.get(id); String realPathtoUploads = "/home/brennan/_repos/rent/src/main/webapp/uploads/" + id; String orgName = file.getOriginalFilename(); rent.setFileName(orgName);/* w w w .j av a2 s.co m*/ forRentDao.addPhotos(id, orgName); String filePath = (realPathtoUploads + rent.getId() + "_" + orgName); File dest = new File(filePath); file.transferTo(dest); return "home"; } return "home"; }
From source file:org.openmrs.module.dhisconnector.web.controller.DHISConnectorController.java
@RequestMapping(value = "/module/dhisconnector/dhis2BackupImport", method = RequestMethod.POST) public void backupDHIS2APIImport(ModelMap model, @RequestParam(value = "dhis2APIbBackup", required = false) MultipartFile dhis2APIbBackup) { if (StringUtils.isNotBlank(dhis2APIbBackup.getOriginalFilename()) && dhis2APIbBackup.getOriginalFilename().endsWith(".zip")) { String msg = Context.getService(DHISConnectorService.class).uploadDHIS2APIBackup(dhis2APIbBackup); if (msg.startsWith("Successfully")) { failureOrSuccessFeedback(model, "", msg); } else {/*from w ww. j a va 2 s . com*/ failureOrSuccessFeedback(model, msg, ""); } } else { failureOrSuccessFeedback(model, Context.getMessageSourceService().getMessage("dhisconnector.dhis2backup.wrongUpload"), ""); } }