List of usage examples for org.springframework.web.multipart MultipartFile isEmpty
boolean isEmpty();
From source file:net.shopxx.controller.admin.ThemeController.java
@RequestMapping(value = "/setting", method = RequestMethod.POST) public String setting(String id, MultipartFile themeFile, RedirectAttributes redirectAttributes) { if (themeFile != null && !themeFile.isEmpty()) { if (!FilenameUtils.isExtension(themeFile.getOriginalFilename(), "zip")) { addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid")); return "redirect:setting.jhtml"; }/*from w ww.j a v a 2 s . co m*/ if (!themeService.upload(themeFile)) { addFlashMessage(redirectAttributes, Message.error("admin.theme.uploadInvalid")); return "redirect:setting.jhtml"; } } Theme theme = themeService.get(id); if (theme == null) { return ERROR_VIEW; } Setting setting = SystemUtils.getSetting(); setting.setTheme(theme.getId()); SystemUtils.setSetting(setting); cacheService.clear(); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:setting.jhtml"; }
From source file:de.science.hack.jetstream.web.controller.UploadController.java
/** * Upload a single file and process the content * * @param file the actual content// w w w . j a va 2 s . com * @return the result as String */ @RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody ModelAndView upload(@RequestParam("file") MultipartFile file) { ModelAndView model; if (!file.isEmpty()) { try { byte[] bytes = file.getBytes(); WindModelBuilder builder = new WindModelBuilder(); TriangleMesh mesh = builder.build(bytes); resultCache.setMesh(mesh); model = new ModelAndView(WEBGL_VIEW); } catch (IOException e) { LOG.warn(e.getMessage(), e); model = new ModelAndView(FAILED_VIEW, MSG_OBJ, e.getMessage()); } } else { model = new ModelAndView(FAILED_VIEW, MSG_OBJ, FAILED_UPLOAD); } return model; }
From source file:org.bonitasoft.web.designer.controller.ImportController.java
private void checkFilePartIsPresent(MultipartFile file) { if (file == null || file.isEmpty()) { throw new IllegalArgumentException("Part named [file] is needed to successfully import a component"); }/*from w w w . j a v a2s . c o m*/ }
From source file:com.redhat.rhtracking.web.controller.UploadController.java
@ResponseBody @RequestMapping(value = "/upload", method = RequestMethod.POST) public String handleFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { String r = "--- upload ---\n"; try {//ww w.j a v a 2s . c om if (!file.isEmpty()) { byte[] bytes = file.getBytes(); r += "file uploaded\n"; r += "name: " + name + "\n"; r += new String(bytes) + "\n"; } else { r += "got empty file"; } } catch (IOException | NullPointerException ex) { r += "--IOException|NullPointerException--\n" + ex + "\n"; } return r + "---end---"; }
From source file:service.PaymentService.java
public ServiceResult save(Payment payment, Long orderId, MultipartFile[] files) throws IOException { Order order = orderDao.find(orderId); String username = AuthManager.getUserName(); User user = userDao.getUserByLogin(username); payment.setUser(user);// ww w . j a va 2s . c o m payment.setPaymentDate(new Date()); payment.setOrder(order); payment.setFinalPayment(isFinalPayment(payment, order)); ServiceResult result = validateSave(payment, paymentDao); if (!result.hasErrors()) { if (files != null) { for (MultipartFile file : files) { if (file != null && !file.isEmpty()) { PaymentFile fileEntity = new PaymentFile(); fileEntity.setPayment(payment); saveFile(fileEntity, file); } } } } return result; }
From source file:com.baifendian.swordfish.webserver.service.storage.FileSystemStorageService.java
/** * ?, // w w w . j a va 2 s. c om * * @param file * @param destFilename */ @Override public void store(MultipartFile file, String destFilename) { try { if (file.isEmpty()) { throw new StorageException("Failed to store empty file " + file.getOriginalFilename()); } File destFile = new File(destFilename); File destDir = new File(destFile.getParent()); if (!destDir.exists()) { FileUtils.forceMkdir(destDir); } Files.copy(file.getInputStream(), Paths.get(destFilename)); } catch (IOException e) { throw new StorageException("Failed to store file " + file.getOriginalFilename(), e); } }
From source file:org.dineth.shooter.app.view.ImageController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody/*from w w w . ja v a2s .c o m*/ public String handleFormUpload(@RequestParam("file") MultipartFile file) { File destination = null; if (!file.isEmpty()) { try { BufferedImage src = ImageIO.read(new ByteArrayInputStream(file.getBytes())); destination = new File(homefilefolder + file.getOriginalFilename()); destination.mkdirs(); ImageIO.write(src, FilenameUtils.getExtension(file.getOriginalFilename()), destination); //Save the id you have used to create the file name in the DB. You can retrieve the image in future with the ID. } catch (IOException ex) { Logger.getLogger(ImageController.class.getName()).log(Level.SEVERE, null, ex); } } else { return "bad thing"; } return destination.getName(); }
From source file:app.springapp.FileUploadController.java
/** * Upload single file using Spring Controller */// w ww .j av a 2s. c o m @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) public @ResponseBody ModelAndView uploadFileHandler(@RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try { img_conv.setOriginalImage(convert(file)); ModelAndView convert = new ModelAndView("convert"); int n = getMaxMessageLength(); String _n = Integer.toString(n); convert.addObject("maxLen", _n); convert.addObject("img_conv", img_conv); return convert; } catch (Exception e) { return new ModelAndView("error"); } } else { return new ModelAndView("error"); } }
From source file:com.trenako.web.images.validation.ImageValidator.java
@Override public boolean isValid(MultipartFile file, ConstraintValidatorContext context) { // skip validation for empty files. if (file == null || file.isEmpty()) return true; // validate file size if (file.getSize() > AppGlobals.MAX_UPLOAD_SIZE) { return false; }//www. j av a 2 s .c o m // validate content type MediaType contentType = MediaType.parseMediaType(file.getContentType()); if (!AppGlobals.ALLOWED_MEDIA_TYPES.contains(contentType.toString())) { return false; } return true; }
From source file:webcomicreader.webapp.controller.BackupRestoreController.java
@RequestMapping(value = "/uploadToDb", method = RequestMethod.POST) public String uploadToDatabase(@RequestParam("file") MultipartFile file, Model model) throws IOException { boolean successful; if (!file.isEmpty()) { String fileStr = new String(file.getBytes(), "UTF-8"); storage.reloaddb(fileStr);//from w w w.ja v a2s . com successful = true; } else { successful = false; } model.addAttribute("successful", successful); return "loaddbResults"; }