List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename
@Nullable String getOriginalFilename();
From source file:app.springapp.FileUploadController.java
public BufferedImage convert(MultipartFile file) { BufferedImage im = null;/* w w w . j a va2s . c o m*/ File convFile = new File(file.getOriginalFilename()); try { convFile.createNewFile(); FileOutputStream fos = new FileOutputStream(convFile); fos.write(file.getBytes()); fos.close(); im = ImageIO.read(convFile); } catch (IOException e) { } return im; }
From source file:ru.mystamps.web.validation.jsr303.NotEmptyFilenameValidator.java
@Override public boolean isValid(MultipartFile file, ConstraintValidatorContext ctx) { if (file == null) { return true; }// ww w. ja v a2 s .com boolean emptyFilename = StringUtils.isEmpty(file.getOriginalFilename()); return !emptyFilename; }
From source file:com.casker.portfolio.domain.Portfolio.java
public void setThumbnailImage(MultipartFile thumbnailImage) { this.thumbnailImage = thumbnailImage; this.thumbnail = "/thumbnail/" + thumbnailImage.getOriginalFilename(); }
From source file:org.wallride.service.MediaService.java
public Media createMedia(MultipartFile file) { Media media = new Media(); media.setMimeType(file.getContentType()); media.setOriginalName(file.getOriginalFilename()); media = mediaRepository.saveAndFlush(media); // Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); try {/*from w w w . j a va 2 s . co m*/ Resource prefix = resourceLoader.getResource(wallRideProperties.getMediaLocation()); Resource resource = prefix.createRelative(media.getId()); // AmazonS3ResourceUtils.writeMultipartFile(file, resource); ExtendedResourceUtils.write(resource, file); } catch (IOException e) { throw new RuntimeException(e); } return media; }
From source file:com.juliuskrah.multipart.web.UserController.java
@PostMapping("/profile") public String index(@ModelAttribute Account account, @RequestParam("file") MultipartFile file, Errors errors) { if (errors.hasErrors()) { return "profile"; }//from ww w .j a v a 2 s. c om log.debug("Filename is {}", file.getOriginalFilename()); return "redirect:/u/profile"; }
From source file:no.dusken.aranea.service.StoreImageServiceImpl.java
public Image changeImage(MultipartFile mFile, Image image) throws IOException { File file = new File(imageDirectory + "/tmp/" + mFile.getOriginalFilename()); log.debug("creating file {}", file.getAbsolutePath()); // ensure the needed directories are present: file.getParentFile().mkdirs();//w w w . j a v a2s. c o m mFile.transferTo(file); return changeImage(file, image); }
From source file:org.sakaiproject.imagegallery.integration.standalone.FileLibraryStandalone.java
/** * @see org.sakaiproject.imagegallery.integration.FileLibraryService#storeImageFile(org.springframework.web.multipart.MultipartFile) *///from w w w. j ava 2 s . c o m @Transactional public ImageFile storeImageFile(final MultipartFile sourceImageFile) { final String filename = sourceImageFile.getOriginalFilename(); final String fileId = contextService.getCurrentContextUid() + "/" + filename; final String contentType = sourceImageFile.getContentType(); ImageFile imageFile = new ImageFile(); imageFile.setContentType(contentType); imageFile.setFilename(filename); imageFile.setFileId(fileId); imageFile.setDataUrl(urlPrefix + fileId); jdbcTemplate.getJdbcOperations().execute( "insert into IMAGE_GALLERY_STANDALONE_FILES_T (FILE_ID, CONTENT_TYPE, CONTENT) VALUES (?, ?, ?)", new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException { ps.setString(1, fileId); ps.setString(2, contentType); try { lobCreator.setBlobAsBinaryStream(ps, 3, sourceImageFile.getInputStream(), (int) sourceImageFile.getSize()); } catch (IOException e) { log.error("Error copying binary data from file " + filename, e); } } }); return imageFile; }
From source file:edu.mayo.xsltserver.controller.AdminController.java
/** * upload.//from w ww. j a v a 2 s.c om * * @param request the request * @param response the response * @return the redirect view * @throws Exception the exception */ @RequestMapping(value = "/admin/files", method = RequestMethod.POST) public RedirectView upload(HttpServletRequest request, HttpServletResponse response) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("file"); String fileName = multipartFile.getOriginalFilename(); fileService.store(fileName, multipartFile.getBytes()); RedirectView view = new RedirectView("../admin"); view.setExposeModelAttributes(false); return view; }
From source file:com.castlemock.web.basis.manager.FileManager.java
/** * The method uploads a list of MultipartFiles to the server. The output file directory is configurable and can be * configured in the main property file under the key "temp.file.directory" * @param files The list of files that should be uploaded * @return Returns the uploaded files as a list of files. The files have the new server path. * @throws IOException Throws an exception if the upload fails. *///from www . java 2 s.c om public List<File> uploadFiles(final List<MultipartFile> files) throws IOException { final File fileDirectory = new File(tempFilesFolder); if (!fileDirectory.exists()) { fileDirectory.mkdirs(); } final List<File> uploadedFiles = new ArrayList<File>(); LOGGER.debug("Starting uploading files"); for (MultipartFile file : files) { if (file.getOriginalFilename().isEmpty()) { continue; } LOGGER.debug("Uploading file: " + file.getOriginalFilename()); final File serverFile = new File( fileDirectory.getAbsolutePath() + File.separator + file.getOriginalFilename()); final byte[] bytes = file.getBytes(); final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); try { stream.write(bytes); uploadedFiles.add(serverFile); } finally { stream.close(); } } return uploadedFiles; }
From source file:com.lixiaocong.rest.FileController.java
@RolesAllowed("ROLE_USER") @RequestMapping(value = "/upload", method = RequestMethod.POST) public String post(MultipartFile imageFile) { try {//from ww w . j a va 2s . co m File newFile = new File(imageFolder + UUID.randomUUID() + imageFile.getOriginalFilename()); imageFile.transferTo(newFile); return imageServer + newFile.getName(); } catch (Exception e) { logger.error(e); } return imageServer + "error.jpg"; }