List of usage examples for org.springframework.web.multipart MultipartFile isEmpty
boolean isEmpty();
From source file:com.xiovr.unibot.web.controller.ManageController.java
@RequestMapping(value = "/env/uploadcryptor", method = RequestMethod.POST) public @ResponseBody String cryptoreFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try {//from w w w.j a v a 2 s .com byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream( new File(botGameConfig.getAbsDirPath() + "/" + BotEnvironment.LIBS_PATH + "/" + name))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + " into " + name + "-uploaded !"; } catch (Exception e) { return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } }
From source file:csns.util.FileIO.java
public File save(MultipartFile uploadedFile, User user, File parent, boolean isPublic) { if (uploadedFile.isEmpty()) return null; File file = new File(); file.setName(uploadedFile.getOriginalFilename()); file.setType(uploadedFile.getContentType()); file.setSize(uploadedFile.getSize()); file.setOwner(user);/*from w w w . ja va 2 s.co m*/ file.setParent(parent); file.setPublic(isPublic); file = fileDao.saveFile(file); java.io.File diskFile = getDiskFile(file, false); try { uploadedFile.transferTo(diskFile); } catch (Exception e) { logger.error("Failed to save uploaded file", e); } return file; }
From source file:ro.cornholio.vision.text.TextApp.java
@RequestMapping(method = RequestMethod.POST, value = "/") public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) { if (!file.isEmpty()) { try {// w w w. java 2 s. c o m byte[] bytes = IOUtils.toByteArray(file.getInputStream()); List<ImageText> texts = detectText(bytes); for (ImageText txt : texts) { for (EntityAnnotation annotation : txt.textAnnotations()) { System.out.println(annotation.getDescription()); } } redirectAttributes.addFlashAttribute("message", "You successfully uploaded !"); } catch (IOException | RuntimeException e) { redirectAttributes.addFlashAttribute("message", "Failed to upload => " + e.getMessage()); } } else { redirectAttributes.addFlashAttribute("message", "Failed to upload because it was empty"); } return "redirect:/"; }
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 ww w. j a v a2 s. com*/ 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:controllers.BaseParamController.java
@RequestMapping("/updateFromXml") public String updateFromXml(Map<String, Object> model, @RequestParam(value = "xlsFile", required = false) MultipartFile file, RedirectAttributes ras) { if (file == null || file.isEmpty()) { ras.addFlashAttribute("error", "File not found"); } else {//w w w. j a v a2 s .co m File newFile = new File("/usr/local/etc/BaseParamMap"); if (newFile.exists()) { newFile.delete(); } try { FileUtils.writeByteArrayToFile(newFile, file.getBytes()); baseParamService.updateFromXml(newFile); ras.addFlashAttribute("error", baseParamService.getResult().getErrors()); } catch (Exception e) { ras.addFlashAttribute("error", "updateFromXml" + StringAdapter.getStackTraceException(e)/*e.getMessage()*/); } if (newFile.exists()) { newFile.delete(); } } return "redirect:/BaseParam/show"; }
From source file:com.aboutdata.service.bean.ImageGraphicsServiceImpl.java
@Override @Deprecated// w ww .ja va 2s .co m public void build(Photos photos, MultipartFile multipartFile) { if (multipartFile != null && !multipartFile.isEmpty()) { try { File tempFile = new File( System.getProperty("java.io.tmpdir") + "/upload_" + multipartFile.getOriginalFilename()); if (!tempFile.getParentFile().exists()) { tempFile.getParentFile().mkdirs(); } multipartFile.transferTo(tempFile); //addTask(sourcePath, largePath, mediumPath, thumbnailPath, tempFile, multipartFile.getContentType()); String path = storageService.upload(tempFile); //?? wallhaven? //Random r1 = new Random(); //int num = r1.nextInt(19) + 1; //String thumbnail = "http://themes.mediacreed.com/html/synergy/assets/media/galleries/image_gallery/thumbs/thumb" + num + ".jpg"; //String medium = "http://themes.mediacreed.com/html/synergy/assets/media/galleries/image_gallery/images/image" + num + ".jpg"; /** * EasyImage?? */ EasyImage image = new EasyImage(tempFile); float width = image.getWidth(); //?? int resize = (int) ((200 / width) * 100); image.resize(resize); //? image.saveAs("/tmp/" + tempFile.getName()); File tempThumbnail = new File("/tmp/" + tempFile.getName()); String thumbnail = storageService.upload(tempThumbnail); //? tempThumbnail.delete(); } catch (IOException | IllegalStateException e) { e.printStackTrace(); } } }
From source file:net.groupbuy.service.impl.ProductImageServiceImpl.java
public void build(ProductImage productImage) { MultipartFile multipartFile = productImage.getFile(); if (multipartFile != null && !multipartFile.isEmpty()) { try {//w ww. j a v a 2 s . c om Setting setting = SettingUtils.get(); Map<String, Object> model = new HashMap<String, Object>(); model.put("uuid", UUID.randomUUID().toString()); String uploadPath = FreemarkerUtils.process(setting.getImageUploadPath(), model); String uuid = UUID.randomUUID().toString(); String sourcePath = uploadPath + uuid + "-source." + FilenameUtils.getExtension(multipartFile.getOriginalFilename()); String largePath = uploadPath + uuid + "-large." + DEST_EXTENSION; String mediumPath = uploadPath + uuid + "-medium." + DEST_EXTENSION; String thumbnailPath = uploadPath + uuid + "-thumbnail." + DEST_EXTENSION; Collections.sort(storagePlugins); for (StoragePlugin storagePlugin : storagePlugins) { if (storagePlugin.getIsEnabled()) { File tempFile = new File( System.getProperty("java.io.tmpdir") + "/upload_" + UUID.randomUUID() + ".tmp"); if (!tempFile.getParentFile().exists()) { tempFile.getParentFile().mkdirs(); } multipartFile.transferTo(tempFile); addTask(sourcePath, largePath, mediumPath, thumbnailPath, tempFile, multipartFile.getContentType()); productImage.setSource(storagePlugin.getUrl(sourcePath)); productImage.setLarge(storagePlugin.getUrl(largePath)); productImage.setMedium(storagePlugin.getUrl(mediumPath)); productImage.setThumbnail(storagePlugin.getUrl(thumbnailPath)); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:csns.web.validator.ResourceValidator.java
public void validate(Resource resource, MultipartFile uploadedFile, Errors errors) { validate(resource, errors);/*from w ww . j ava 2 s . com*/ if (resource.getType() == ResourceType.FILE && resource.getFile() == null && (uploadedFile == null || uploadedFile.isEmpty())) errors.rejectValue("file", "error.field.required"); }
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 .ja v a 2s . c o 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.fon.documentmanagementsystem.controllers.DocumentController.java
private boolean daLiJePrazan(MultipartFile file) { if (file.isEmpty()) { System.out.println("Fajl prazan"); return true; } else {// w w w.j a v a 2 s . c o m System.out.println("naziv:" + file.getName()); } return false; }