List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:com.glaf.base.modules.todo.springmvc.SysTodoController.java
/** * /*from w w w . ja v a2 s.c o m*/ * * @param request * @param modelMap * @return */ @RequestMapping(params = "method=uploadFile") public ModelAndView uploadFile(HttpServletRequest request, ModelMap modelMap, @RequestParam("file") MultipartFile file) throws Exception { TodoXlsReader reader = new TodoXlsReader(); List<Todo> todos = reader.readXls(file.getInputStream()); if (todos != null && !todos.isEmpty()) { logger.debug("import size:" + todos.size()); for (Todo todo : todos) { todo.setEnableFlag(1); } todoService.saveAll(todos); } return this.showList(modelMap, request); }
From source file:de.yaio.services.metaextract.server.controller.MetaExtractController.java
/** * extract metadata from the uploaded file * @param uploadFile the file to extract metadata from * @param lang the prevered lang to parse (OCR) * @return the extracted metadata * @throws IOException possible *//*from ww w.j av a 2 s . c om*/ @RequestMapping(method = RequestMethod.POST, value = "/getByFile") public @ResponseBody ExtractedMetaData getByFile(@RequestParam("file") MultipartFile uploadFile, @RequestParam("lang") String lang) throws IOException, ExtractorException { return metaExtractFacade.extractMetaData(uploadFile.getInputStream(), uploadFile.getOriginalFilename(), lang); }
From source file:com.qubit.solution.fenixedu.bennu.webservices.ui.management.keystores.UploadKeyStoreController.java
@RequestMapping(value = "/upload/{oid}", method = RequestMethod.POST) public String uploadkeystoreToUpload(@PathVariable("oid") DomainKeyStore domainKeyStore, @RequestParam(value = "keyStoreFile", required = false) MultipartFile keyStoreFile, Model model) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try {/*from w w w. ja v a 2s . co m*/ StreamUtils.copy(keyStoreFile.getInputStream(), byteArrayOutputStream); } catch (IOException e) { e.printStackTrace(); } byte[] content = byteArrayOutputStream.toByteArray(); changeKeystore(domainKeyStore, content); return "redirect:/webservices/management/keystores/domainkeystore/read/" + domainKeyStore.getExternalId(); }
From source file:org.magnum.dataup.VideoService.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST) public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id, @RequestParam("data") MultipartFile data, HttpServletResponse response) { Video v = videos.get(id);/*from w ww .j a va 2s.co m*/ try { vfm.saveVideoData(v, data.getInputStream()); } catch (Exception e) { sendError(response, 404, "Video data could not be saved."); return null; } return new VideoStatus(VideoStatus.VideoState.READY); }
From source file:com.intuit.karate.demo.controller.UploadController.java
@PostMapping public @ResponseBody FileInfo upload(@RequestParam("file") MultipartFile multipartFile, @RequestParam String name) throws Exception { String uuid = UUID.randomUUID().toString(); String filePath = FILES_BASE + uuid; FileUtils.copyToFile(multipartFile.getInputStream(), new File(filePath)); FileUtils.writeStringToFile(new File(filePath + "_meta.txt"), name, "utf-8"); return new FileInfo(uuid, name); }
From source file:alfio.controller.api.EventApiController.java
@RequestMapping(value = "/events/{eventName}/pending-payments/bulk-confirmation", method = POST) public List<Triple<Boolean, String, String>> bulkConfirmation(@PathVariable("eventName") String eventName, Principal principal, @RequestParam("file") MultipartFile file) throws IOException { try (InputStreamReader isr = new InputStreamReader(file.getInputStream())) { CSVReader reader = new CSVReader(isr); String username = principal.getName(); return reader.readAll().stream().map(line -> { String reservationID = null; try { Validate.isTrue(line.length >= 2); reservationID = line[0]; eventManager.confirmPayment(eventName, reservationID, new BigDecimal(line[1]), username); return Triple.of(Boolean.TRUE, reservationID, ""); } catch (Exception e) { return Triple.of(Boolean.FALSE, Optional.ofNullable(reservationID).orElse(""), e.getMessage()); }// ww w.j a v a2 s . co m }).collect(Collectors.toList()); } }
From source file:org.pdfgal.pdfgalweb.validators.MergeValidator.java
/** * Makes the validation for a single ZIP file * /*ww w . j a v a2s .co m*/ * @param file * @param errors */ private void validateZipFile(final MultipartFile file, final Errors errors) { try { InputStream fileInputStream = file.getInputStream(); if (!this.zipUtils.isZip(fileInputStream)) { // In case the file is not ZIP we show error, file must be a // ZIP errors.rejectValue("files", "merge.validator.files.incorrect.zip"); } else { // If file is ZIP, every file inside must be PDF List<String> urisList = new ArrayList<String>(); // InputStream is closed previously so we must get it again fileInputStream = file.getInputStream(); urisList = this.zipUtils.saveFilesFromZip(fileInputStream); for (final String uri : urisList) { if (!this.pdfGalValidator.isPDF(uri)) { errors.rejectValue("files", "merge.validator.files.incorrect.zip.pdf"); break; } if (this.pdfGalValidator.isEncrypted(uri)) { errors.rejectValue("files", "merge.validator.files.incorrect.zip.encrypted"); break; } } this.fileUtils.delete(urisList); } fileInputStream.close(); } catch (final IOException e) { errors.rejectValue("files", "merge.validator.files.incorrect.zip"); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.controllers.ProfileController.java
@RequestMapping(value = "/{settingsId}/profile/", method = RequestMethod.POST) public String loadProfile(Model model, @PathVariable("settingsId") String settingsId, @RequestParam("profile") MultipartFile file) throws UnsupportedEncodingException { try {//from w ww.ja v a2 s .com Profile profile = marshaller.unmarshal(new StreamSource(file.getInputStream())); Settings settings = profile.getSettings(); settings.setEid(settingsId); settings.applyParentToChildren(); settingsService.updateLocalSettings(settings); model.addAttribute("message", "profile-loaded"); return "redirect:/app/" + UriUtils.encodePathSegment(settingsId, "UTF-8") + "/"; } catch (Exception e) { logger.warn("Error loading profile", e); model.addAttribute("message", "error-loading-profile"); return "redirect:/app/" + UriUtils.encodePathSegment(settingsId, "UTF-8") + "/"; } }
From source file:com.qubit.solution.fenixedu.bennu.webservices.ui.management.keystores.UploadCertificateController.java
@RequestMapping(value = "/upload/{oid}", method = RequestMethod.POST) public String uploadcertificateToCancel(@PathVariable("oid") DomainKeyStore domainKeyStore, @RequestParam(value = "certificateAlias", required = false) String alias, @RequestParam(value = "certificateFile", required = false) MultipartFile certificateFile, Model model) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try {/*from w ww .j a va 2s . c o m*/ StreamUtils.copy(certificateFile.getInputStream(), byteArrayOutputStream); } catch (IOException e) { e.printStackTrace(); } byte[] content = byteArrayOutputStream.toByteArray(); addCertificateToKeyStore(domainKeyStore, alias, content); return "redirect:/webservices/management/keystores/domainkeystore/read/" + domainKeyStore.getExternalId(); }
From source file:org.openxdata.server.servlet.ImportServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*w w w . ja v a2 s .com*/ String importType = request.getParameter("type"); String filecontents = null; CommonsMultipartResolver multipartResover = new CommonsMultipartResolver(/*this.getServletContext()*/); if (multipartResover.isMultipart(request)) { MultipartHttpServletRequest multipartRequest = multipartResover.resolveMultipart(request); MultipartFile uploadedFile = multipartRequest.getFile("filecontents"); if (uploadedFile != null && !uploadedFile.isEmpty()) { filecontents = IOUtils.toString(uploadedFile.getInputStream()); } } if (filecontents != null) { log.info("Starting import of type: " + importType); if (importType.equals("user")) { String errors = userService.importUsers(filecontents); if (errors != null) { writeErrorsToResponse(errors, response); } } else { log.warn("Unknown import type: " + importType); } } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getOutputStream().print(ex.getMessage()); } }