List of usage examples for org.springframework.web.multipart MultipartFile getInputStream
@Override
InputStream getInputStream() throws IOException;
From source file:eu.europa.ec.grow.espd.controller.EspdController.java
private String reuseRequestAsCA(MultipartFile attachment, Model model, BindingResult result) throws IOException { try (InputStream is = attachment.getInputStream()) { Optional<EspdDocument> espd = exchangeMarshaller.importEspdRequest(is); if (espd.isPresent()) { model.addAttribute("espd", espd.get()); return redirectToPage(REQUEST_CA_PROCEDURE_PAGE); }/*w ww.ja v a 2s . c om*/ } result.rejectValue("attachments", "espd_upload_request_error"); return "filter"; }
From source file:eu.europa.ec.grow.espd.controller.EspdController.java
private String reviewResponseAsCA(MultipartFile attachment, Model model, BindingResult result) throws IOException { try (InputStream is = attachment.getInputStream()) { Optional<EspdDocument> espd = exchangeMarshaller.importEspdResponse(is); if (espd.isPresent()) { model.addAttribute("espd", espd.get()); return redirectToPage(PRINT_PAGE); }/*from w w w.j a v a2s .c om*/ } result.rejectValue("attachments", "espd_upload_response_error"); return "filter"; }
From source file:net.solarnetwork.node.setup.web.NodeCertificatesController.java
/** * Import a certificate reply (signed certificate chain). * //from ww w . j av a 2s.co m * @param file * the CSR file to import * @return the destination view * @throws IOException * if an IO error occurs */ @RequestMapping(value = "/import", method = RequestMethod.POST) public String importSettings(@RequestParam(value = "file", required = false) MultipartFile file, @RequestParam(value = "text", required = false) String text) throws IOException { String pem = text; if (file != null && !file.isEmpty()) { pem = FileCopyUtils.copyToString(new InputStreamReader(file.getInputStream(), "UTF-8")); } pkiService.saveNodeSignedCertificate(pem); return "redirect:/certs"; }
From source file:com.vsquaresystem.safedeals.marketprice.MarketPriceService.java
@Transactional(readOnly = false) public Boolean insertAttachments(MultipartFile attachmentMultipartFile) throws JsonProcessingException, IOException { File outputFile = attachmentUtils.storeAttachmentByAttachmentType( attachmentMultipartFile.getOriginalFilename(), attachmentMultipartFile.getInputStream(), AttachmentUtils.AttachmentType.MARKET_PRICE); return outputFile.exists(); }
From source file:eu.europa.ec.grow.espd.controller.EspdController.java
private String importEspdAsEo(Country country, MultipartFile attachment, Model model, BindingResult result) throws IOException { try (InputStream is = attachment.getInputStream()) { Optional<EspdDocument> wrappedEspd = exchangeMarshaller.importAmbiguousEspdFile(is); // how can wrappedEspd be null??? if (wrappedEspd != null && wrappedEspd.isPresent()) { EspdDocument espd = wrappedEspd.get(); if (espd.getEconomicOperator() == null) { espd.setEconomicOperator(new EconomicOperatorImpl()); }/* w w w . j a v a 2 s. c o m*/ if (needsToLoadProcurementProcedureInformation(espd)) { // in this case we need to contact TED again to load the procurement information copyTedInformation(espd); } espd.getEconomicOperator().setCountry(country); model.addAttribute("espd", espd); return redirectToPage(RESPONSE_EO_PROCEDURE_PAGE); } } result.rejectValue("attachments", "espd_upload_error"); return "filter"; }
From source file:cherry.foundation.async.AsyncFileProcessHandlerImpl.java
private File createFile(MultipartFile file) throws IOException { File tempFile = createTempFile(format(tempPrefix, LocalDateTime.now().toDate()), tempSuffix, tempDir); tempFile.deleteOnExit();//w ww . j av a2 s .c om try { try (InputStream in = file.getInputStream(); OutputStream out = new FileOutputStream(tempFile)) { ByteStreams.copy(in, out); return tempFile; } } catch (IOException ex) { deleteFile(tempFile); throw ex; } }
From source file:org.openmrs.module.moduledistro.web.controller.ModuleDistroManagementController.java
@RequestMapping(value = "/module/moduledistro/manage-upload", method = RequestMethod.POST) public void handleUpload(@RequestParam("distributionZip") MultipartFile uploaded, HttpServletRequest request, Model model) {/*from ww w .j a v a 2 s. c om*/ // write this to a known file on disk, so we can use ZipFile, since ZipInputStream is buggy File file = null; try { file = File.createTempFile("distribution", ".zip"); file.deleteOnExit(); FileUtils.copyInputStreamToFile(uploaded.getInputStream(), file); } catch (Exception ex) { throw new RuntimeException("Error getting uploaded data", ex); } List<String> log = Context.getService(ModuleDistroService.class).uploadDistro(file, request.getSession().getServletContext()); model.addAttribute("log", log); }
From source file:com.epam.catgenome.controller.AbstractRESTController.java
/** * Joins back the file, transferred by chunks. * * @param multipart {@code Multipart} used to handle file chunk upload * @param id {@code Integer} identifies a specific file * @param fileName {@code String} original file name * @param chunk {@code int} current chunk number * @param chunks {@code int} overall number of chunks * @return {@code File} represents a reference on a temporary file that has been created * @throws IOException//from ww w.j ava 2 s. com */ protected File saveChunkedFile(MultipartFile multipart, Integer id, String fileName, int chunk, int chunks) throws IOException { File dst = new File(fileManager.getTempDir(), id + fileName); if (Objects.equals(chunk, chunks - 1)) { FileUtils.forceDeleteOnExit(dst); } try (InputStream inputStream = multipart.getInputStream(); OutputStream out = dst.exists() ? new BufferedOutputStream(new FileOutputStream(dst, true), BUF_SIZE) : new BufferedOutputStream(new FileOutputStream(dst), BUF_SIZE);) { byte[] buffer = new byte[BUF_SIZE]; int len = 0; while ((len = inputStream.read(buffer)) > 0) { out.write(buffer, 0, len); } } return dst; }
From source file:org.hydroponics.dao.JDBCHydroponicsDaoImpl.java
@Override public void saveImage(int grow, MultipartFile image) { logger.info("save image"); try {//from w w w . j av a2s .c om BufferedImage buffImage = ImageIO.read(image.getInputStream()); this.jdbcTemplate.update( "insert into IMAGE (GROW_ID, timestamp, height, width, mimeType, thumbnail, image) values (?, ?, ?, ?, ?, ?, ?)", new Object[] { grow, new Timestamp(System.currentTimeMillis()), buffImage.getHeight(), buffImage.getWidth(), "image/jpeg", getThumbnail(buffImage), image.getBytes() }); } catch (IOException ex) { logger.severe(ex.toString()); } }