List of usage examples for org.springframework.web.multipart MultipartFile isEmpty
boolean isEmpty();
From source file:cs425.yogastudio.controller.ProductController.java
@RequestMapping(value = "/addProduct", method = RequestMethod.POST) public String addProduct(String productName, String price, String description, Model model, HttpSession session, @RequestParam("file") MultipartFile file) { double thePrice = Double.parseDouble(price); Product newProduct = new Product(productName, thePrice, description); if (!file.isEmpty()) { try {/*from w w w. j a v a 2 s . com*/ newProduct.setProductImage(file.getBytes()); } catch (IOException e) { e.printStackTrace(); } } productService.addProduct(newProduct); model.addAttribute("added", newProduct.getProductName()); session.setAttribute("added", newProduct.getProductName()); return "redirect:/addProductSuccess"; }
From source file:com.portal.controller.AdminController.java
@RequestMapping(value = "/employes/create", method = RequestMethod.POST) public String submitCreateEmployee(HttpServletRequest request, @ModelAttribute("employeedto") EmployeeDTO employeedto, @RequestParam(value = "avatarFile", required = false) MultipartFile avatar) throws Exception { Employee employee = new Employee(); if (!avatar.isEmpty() && avatar.getContentType().equals("image/jpeg")) { portalService.saveFile(//ww w .j av a 2 s. c o m request.getServletContext().getRealPath("/template/img/") + "/" + avatar.getOriginalFilename(), avatar); employee.setAvatar(avatar.getOriginalFilename()); } if (employeedto.getName() == null || employeedto.getName().trim().length() == 0 || employeedto.getPosition() == 0 || employeedto.getDepartment() == 0) { return "redirect:/admin/employes"; } employee.setName(employeedto.getName()); employee.setDepartment(portalService.getDepartment(employeedto.getDepartment())); employee.setPosition(portalService.getPosition(employeedto.getPosition())); employee.setPhone(employeedto.getPhone()); employee.setEmail(employeedto.getEmail()); employee.setDescription(employeedto.getDescription()); portalService.saveEmployee(employee); return "redirect:/admin/employes"; }
From source file:com.github.carlomicieli.nerdmovies.controllers.MovieController.java
@RequestMapping(method = RequestMethod.POST) public String save(@Valid @ModelAttribute Movie movie, @RequestParam("file") MultipartFile file, BindingResult result, Model model) throws IOException { if (result.hasErrors()) { model.addAttribute(movie);/*from ww w.java 2s. co m*/ return "movie/new"; } if (!file.isEmpty()) { movie.setPoster(convert(file)); movie.setThumb(createThumbnail(file, 100)); } movieService.save(movie); return "redirect:movies"; }
From source file:service.ArticleService.java
public ServiceResult update(Article obj, MultipartFile file, boolean deleteFile) throws IOException { ServiceResult res = new ServiceResult(); if (deleteFile) { delFile(obj.getArticleId());// ww w. j av a2s . co m } res = validateUpdate(obj, dao); if (file != null && !file.isEmpty()) { delFile(obj.getArticleId()); ArticleFile newFileEnt = new ArticleFile(); newFileEnt.setArticle(obj); newFileEnt.setRusname(file.getOriginalFilename()); saveFile(newFileEnt, file); } return res; }
From source file:org.openbaton.nfvo.api.RestVNFPackage.java
/** * Adds a new VNFPackage to the VNFPackages repository *//*from ww w .j ava2 s. co m*/ @RequestMapping(method = RequestMethod.POST) @ResponseBody public String onboard(@RequestParam("file") MultipartFile file, @RequestHeader(value = "project-id") String projectId) throws IOException, VimException, NotFoundException, SQLException, PluginException { log.debug("Onboarding"); if (!file.isEmpty()) { byte[] bytes = file.getBytes(); VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor = vnfPackageManagement.onboard(bytes, projectId); return "{ \"id\": \"" + virtualNetworkFunctionDescriptor.getVnfPackageLocation() + "\"}"; } else throw new IOException("File is empty!"); }
From source file:com.capstone.giveout.controllers.GiftsController.java
private void saveImages(Gift gift, MultipartFile image) throws IOException { if (image == null || image.isEmpty()) return;//from w w w .jav a2s.c o m BufferedImage img = ImageIO.read(image.getInputStream()); ImageFileManager imgMan = ImageFileManager.get(GIFT_ROOT_PATH); imgMan.saveImage(gift.getId(), Gift.SIZE_FULL, img); gift.setImageUrlFull(Routes.GIFTS_IMAGE_PATH.replace("{id}", String.valueOf(gift.getId())).replace("{size}", Gift.SIZE_FULL)); BufferedImage scaledImg = Scalr.resize(img, 640); imgMan.saveImage(gift.getId(), Gift.SIZE_MEDIUM, scaledImg); gift.setImageUrlMedium(Routes.GIFTS_IMAGE_PATH.replace("{id}", String.valueOf(gift.getId())) .replace("{size}", Gift.SIZE_MEDIUM)); scaledImg = Scalr.resize(img, 320); imgMan.saveImage(gift.getId(), Gift.SIZE_SMALL, scaledImg); gift.setImageUrlSmall(Routes.GIFTS_IMAGE_PATH.replace("{id}", String.valueOf(gift.getId())) .replace("{size}", Gift.SIZE_SMALL)); gifts.save(gift); }
From source file:com.company.project.web.controller.FileUploadController.java
@RequestMapping(value = "/singleSave", method = RequestMethod.POST) public @ResponseBody String singleSave(@RequestParam("file") MultipartFile file, @RequestParam("desc") String desc) { System.out.println("File Description:" + desc); String fileName = null;/*from www.jav a2s .com*/ if (!file.isEmpty()) { try { fileName = file.getOriginalFilename(); byte[] bytes = file.getBytes(); BufferedOutputStream buffStream = new BufferedOutputStream( new FileOutputStream(new File("C:/cp/" + fileName))); buffStream.write(bytes); buffStream.close(); return "You have successfully uploaded " + fileName; } catch (Exception e) { return "You failed to upload " + fileName + ": " + e.getMessage(); } } else { return "Unable to upload. File is empty."; } }
From source file:controllers.SequenceController.java
@RequestMapping("/updateFromXml") public String updateFromXml(Map<String, Object> model, @RequestParam(value = "xlsFile", required = false) MultipartFile file, @RequestParam(value = "sequenceId", required = true) Long sequenceId, RedirectAttributes ras) { if (file == null || file.isEmpty()) { ras.addFlashAttribute("error", "File not found"); } else {/*from www.ja va 2s . com*/ File newFile = new File("/usr/local/etc/sceneParamsList"); if (newFile.exists()) { newFile.delete(); } try { FileUtils.writeByteArrayToFile(newFile, file.getBytes()); sequenceService.updateFromXml(newFile, sequenceId); ras.addFlashAttribute("error", sequenceService.getResult().getErrors()); } catch (Exception e) { ras.addFlashAttribute("error", "updateFromXml" + StringAdapter.getStackTraceException(e)/*e.getMessage()*/); } if (newFile.exists()) { newFile.delete(); } } ras.addAttribute("sequenceId", sequenceId); return "redirect:/Sequence/showOne"; }
From source file:com.elecnor.ecosystem.serviceimpl.BulkUploadServiceImpl.java
@Override public HashMap<String, Object> uploadFile(MultipartFile fileUploaded, HttpSession session, String className) throws Exception { UserDetail userDetail = (UserDetail) session.getAttribute("selectedUser"); boolean isValidSchema; if (!fileUploaded.isEmpty()) { Workbook workBook = uploadUtility.readExcelFileFromMultipart(fileUploaded); if (workBook == null) { return uploadUtility.getErrorMessage(ConstantUtil.ERROR_FILE_READING_ERROR); }/*from w w w . j a va 2 s . c o m*/ // Schema Validation - Checks Whether Row header name is same as we // specified. // Validate schema only when the document is uploaded and not when // user sends confirmation isValidSchema = uploadUtility.isSchemaValid(workBook, ConstantUtil.SHEETNUM, ConstantUtil.PROJECT_TYPE_HEADER_ROWNUM, className); if (!isValidSchema) { return uploadUtility.getErrorMessage(ConstantUtil.ERROR_HEADER_VALIDATION_ERROR); } // Schema Validation Ends // Check Validation For Confirmation from user-- Pending // Data Validation Starts return saveFile(workBook, className, userDetail); } return null; }
From source file:ca.intelliware.ihtsdo.mlds.web.rest.MemberResource.java
@RequestMapping(value = Routes.MEMBER_BRAND, method = RequestMethod.POST, headers = "content-type=multipart/*", produces = "application/json") @RolesAllowed({ AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN }) @Transactional/*from w w w. j a v a 2s . c o m*/ @Timed public ResponseEntity<?> updateMemberBrand(@PathVariable String memberKey, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("name") String name) throws IOException { Member member = memberRepository.findOneByKey(memberKey); if (multipartFile != null && !multipartFile.isEmpty()) { File licenseFile = updateFile(multipartFile, member.getLogo()); member.setLogo(licenseFile); } member.setName(name); memberRepository.save(member); return new ResponseEntity<MemberDTO>(new MemberDTO(member), HttpStatus.OK); }