List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:org.socialhistoryservices.pid.controllers.QRController.java
@RequestMapping(value = "/qr", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("image") MultipartFile file, HttpServletResponse response) throws IOException { String url = null;//ww w.j a va 2 s.c o m if (!file.isEmpty()) { try { url = qrService.decode(file.getInputStream()); } catch (Exception e) { // Do not do a thing } } if (url == null) { response.setStatus(404); return "fnf400"; } else { response.setStatus(301); response.setHeader("Location", url); response.setHeader("Connection", "close"); return null; } }
From source file:edu.mayo.trilliumbridge.webapp.TransformerController.java
protected void doTransform(HttpServletRequest request, HttpServletResponse response, String acceptHeader, String formatOverride, Transformer transformer) throws IOException { // default to XML if no Accept Header (it should at least be */*, but just in case). if (StringUtils.isBlank(acceptHeader)) { acceptHeader = MediaType.APPLICATION_ATOM_XML_VALUE; }/*ww w. j a v a2 s . c om*/ TrilliumBridgeTransformer.Format responseFormat = null; if (StringUtils.isNotBlank(formatOverride)) { responseFormat = TrilliumBridgeTransformer.Format.valueOf(formatOverride); } else { String[] accepts = StringUtils.split(acceptHeader, ','); for (String accept : accepts) { MediaType askedForType = MediaType.parseMediaType(accept); if (askedForType.isCompatibleWith(MediaType.TEXT_XML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XML)) { responseFormat = TrilliumBridgeTransformer.Format.XML; } else if (askedForType.isCompatibleWith(MediaType.TEXT_HTML) || askedForType.isCompatibleWith(MediaType.APPLICATION_XHTML_XML)) { responseFormat = TrilliumBridgeTransformer.Format.HTML; } else if (askedForType.getType().equals("application") && askedForType.getSubtype().equals("pdf")) { responseFormat = TrilliumBridgeTransformer.Format.PDF; } if (responseFormat != null) { break; } } } if (responseFormat == null) { throw new UserInputException("Cannot return type: " + acceptHeader, HttpStatus.NOT_ACCEPTABLE); } String contentType; switch (responseFormat) { case XML: contentType = MediaType.APPLICATION_XML_VALUE; break; case HTML: contentType = MediaType.TEXT_HTML_VALUE.toString(); break; case PDF: contentType = "application/pdf"; break; default: throw new IllegalStateException("Illegal Response Format"); } InputStream inputStream; if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile(INPUT_FILE_NAME); inputStream = multipartFile.getInputStream(); } else { inputStream = request.getInputStream(); } inputStream = this.checkForUtf8BOMAndDiscardIfAny(this.checkStreamIsNotEmpty(inputStream)); // create a buffer so we don't use the servlet's output stream unless // we get a successful transform, because if we do use it, // we can't use the error view anymore. ByteArrayOutputStream baos = new ByteArrayOutputStream(); transformer.transform(inputStream, baos, responseFormat); try { response.setContentType(contentType); response.getOutputStream().write(baos.toByteArray()); } finally { IOUtils.closeQuietly(baos); } }
From source file:ProcessController.java
/** * ??// w w w . j a va 2 s . co m * @param snakerFile * @param id * @return */ @RequestMapping(value = "deploy", method = RequestMethod.POST) public String processDeploy(@RequestParam(value = "snakerFile") MultipartFile snakerFile, String id) { InputStream input = null; try { input = snakerFile.getInputStream(); if (StringUtils.isNotEmpty(id)) { engine.process().redeploy(id, input); } else { engine.process().deploy(input); } } catch (IOException e) { e.printStackTrace(); } finally { if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } return "redirect:/snaker/process/list"; }
From source file:edu.uiowa.icts.bluebutton.controller.LabTestRangeController.java
@RequestMapping(value = "import", method = RequestMethod.POST) public String importCSV(@RequestParam("file") MultipartFile file) throws IOException { this.bluebuttonDaoService.getLabTestRangeService().importCSV(file.getInputStream()); return "redirect:/labtestrange/"; }
From source file:gr.abiss.calipso.fs.FilePersistenceService.java
public default String saveFile(Field fileField, MultipartFile multipartFile, String filename) { FileDTO file;//from ww w . j a v a 2 s.c o m try { file = new FileDTO.Builder().contentLength(multipartFile.getSize()) .contentType(multipartFile.getContentType()).in(multipartFile.getInputStream()).path(filename) .build(); } catch (IOException e) { throw new RuntimeException("Failed persisting file", e); } return this.saveFile(fileField, file); }
From source file:com.orangeandbronze.jblubble.sample.PersonController.java
protected BlobKey createPhotoBlob(MultipartFile photoFile) { BlobKey blobKey = null;//from w w w.j ava2s . c o m if (photoFile.isEmpty()) { blobKey = null; } else { try { InputStream inputStream = photoFile.getInputStream(); try { blobKey = blobstoreService.createBlob(inputStream, photoFile.getOriginalFilename(), photoFile.getContentType()); } finally { inputStream.close(); } } catch (Exception e) { logger.error("Error saving person's photo", e); } } return blobKey; }
From source file:org.dawnsci.marketplace.services.FileService.java
public File saveSolutionFile(Long solution, MultipartFile file) { String fileName = file.getOriginalFilename(); byte[] buffer = new byte[1000]; File outputFile = getFile(solution.toString(), fileName); outputFile.getParentFile().mkdirs(); try (InputStream reader = file.getInputStream(); FileOutputStream writer = new FileOutputStream(outputFile)) { outputFile.createNewFile();/*from w w w. j a v a 2 s . c o m*/ while ((reader.read(buffer)) != -1) { writer.write(buffer); } return outputFile; } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.laishidua.mobilecloud.ghostmyselfie.controller.GhostMySelfieController.java
public void saveSomeGhostMySelfie(GhostMySelfie gms, MultipartFile ghostMySelfieData) throws IOException { ghostMySelfieDataMgr.saveGhostMySelfieData(gms, ghostMySelfieData.getInputStream()); }
From source file:org.magnum.dataup.AFilledController.java
private void accessData(long id, MultipartFile data, HttpServletResponse res, boolean isSet) { try {/* w ww . j ava 2 s.c o m*/ Video v = mVideos.get(id); if (v == null) throw new IOException(); if (isSet) mVideoDataMgr.saveVideoData(v, data.getInputStream()); else mVideoDataMgr.copyVideoData(v, res.getOutputStream()); } catch (IOException e) { res.setStatus(404); } }
From source file:alfio.controller.api.AdminApiController.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 (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) { String username = principal.getName(); return reader.lines().map(line -> { String reservationID = null; try (Scanner scanner = new Scanner(line)) { scanner.findInLine("([a-zA-Z0-9\\-]+);(\\d+(\\.\\d+)?)"); MatchResult match = scanner.match(); reservationID = match.group(1); eventManager.confirmPayment(eventName, reservationID, new BigDecimal(match.group(2)), username); return Triple.of(Boolean.TRUE, reservationID, ""); } catch (Exception e) { return Triple.of(Boolean.FALSE, Optional.ofNullable(reservationID).orElse(""), e.getMessage()); }/*from w w w . j a v a 2 s . c om*/ }).collect(Collectors.toList()); } }