List of usage examples for org.springframework.web.multipart MultipartFile getBytes
byte[] getBytes() throws IOException;
From source file:de.thb.ue.backend.service.AnswerImageService.java
@Override public void addAnswerImage(Vote vote, MultipartFile answerImage, String evaluationID) { File imageFolder = new File( (workingDirectoryPath.isEmpty() ? "" : (workingDirectoryPath + File.separatorChar)) + evaluationID + File.separatorChar + "images"); try {/* w ww . j av a 2 s . co m*/ if (!imageFolder.exists()) { FileUtils.forceMkdir(imageFolder); } BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File(imageFolder, vote.getId() + ".zip"))); stream.write(answerImage.getBytes()); stream.close(); } catch (IOException e) { //TODO e.printStackTrace(); } }
From source file:com.oak_yoga_studio.controller.CustomerController.java
@RequestMapping(value = "/addCustomer", method = RequestMethod.POST) public String add(@Valid Customer customer, BindingResult result, HttpSession session, RedirectAttributes flashAttr, @RequestParam("file") MultipartFile file) { String view = "redirect:/"; //System.out.println("customerController Add"); if (!result.hasErrors()) { try {//from w ww .ja va2 s .c om customer.setProfilePicture(file.getBytes()); } catch (IOException ex) { Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex); } customerService.addCustomer(customer); session.removeAttribute("credential"); flashAttr.addFlashAttribute("successfulSignup", "Customer signed up succesfully. please log in to proceed"); } else { for (FieldError err : result.getFieldErrors()) { System.out.println("Error:" + err.getField() + ":" + err.getDefaultMessage()); } view = "addCustomer"; } return view; }
From source file:data.repository.pragma.DataObjectController.java
@RequestMapping(value = "/DO/upload", method = RequestMethod.POST) @ResponseBody//w w w .j a v a2s . c o m public MessageResponse DOupload(@RequestParam(value = "data", required = true) MultipartFile file, @RequestParam(value = "metadata", required = true) String metadata) { try { // Create metadata DBObject from input DBObject metadataObject = (DBObject) JSON.parse(metadata); // Ingest multipart file into inputstream byte[] byteArr = file.getBytes(); InputStream inputStream = new ByteArrayInputStream(byteArr); String file_name = file.getOriginalFilename(); String content_type = file.getContentType(); // Connect to MongoDB and use GridFS to store metadata and data // Return created DO internal id in stagingDB String id = Staging_repository.addDO(inputStream, file_name, content_type, metadataObject); MessageResponse response = new MessageResponse(true, id); return response; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); MessageResponse response = new MessageResponse(false, null); return response; } }
From source file:org.openmrs.module.yank.web.controller.QueryController.java
@RequestMapping(method = RequestMethod.POST) public String yank(@RequestParam(value = "server", required = true) String server, @RequestParam(value = "username", required = true) String username, @RequestParam(value = "password", required = true) String password, @RequestParam(value = "datatype", required = true) String datatype, @RequestParam(value = "uuids") String uuids, @RequestParam(value = "file") MultipartFile file, WebRequest request) throws FileNotFoundException, UnsupportedEncodingException, IOException { YankService service = Context.getService(YankService.class); List<String> successes = new ArrayList<String>(); List<String> errors = new ArrayList<String>(); // build uuids from file if it was uploaded if (file != null) { String fileUuids = new String(file.getBytes()); if (!StringUtils.isBlank(fileUuids)) uuids = fileUuids;/* ww w . j a v a2 s . c om*/ } if (StringUtils.isNotEmpty(uuids)) for (String uuid : uuids.split(",")) { // clean it up uuid = uuid.trim(); try { // look it up // TODO encrypt username and password here and decrypt in RestUtil String data = service.yankFromServer(server, username, password, datatype, uuid); if (StringUtils.isBlank(data)) throw new APIException("nothing retrieved from server"); // make a yank out of it Yank yank = new Yank(); yank.setDatatype(datatype); yank.setData(data); yank.setSummary(service.getSummaryForType(datatype, data)); service.saveYank(yank); successes.add("\"" + uuid + "\" successfully yanked."); } catch (Exception ex) { log.warn("error querying for uuid " + uuid, ex); errors.add("\"" + uuid + "\" could not be yanked [" + ex.getLocalizedMessage() + "]"); } } if (!successes.isEmpty()) request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, renderMessage(successes, "Successfully yanked $count items."), WebRequest.SCOPE_SESSION); if (!errors.isEmpty()) request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, renderMessage(errors, "Could not yank $count items. See log for details."), WebRequest.SCOPE_SESSION); return "redirect:process.form"; }
From source file:org.ngrinder.script.controller.FileEntryController.java
private void upload(User user, String path, String description, MultipartFile file) throws IOException { FileEntry fileEntry = new FileEntry(); fileEntry.setContentBytes(file.getBytes()); fileEntry.setDescription(description); fileEntry.setPath(FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename()))); fileEntryService.save(user, fileEntry); }
From source file:controller.InternshipController.java
@RequestMapping(value = "/uploadMultipleFile", method = RequestMethod.POST) public String uploadMultipleFileHandler(@ModelAttribute("SpringWeb") docs.ApplicationModel application, ModelMap model, HttpSession session, @RequestParam("file") MultipartFile[] files) { if (session.getAttribute("userID") != null) { int idUser = (int) session.getAttribute("userID"); STUDENTTYPE user = BusControl.getStudentbyId(idUser); application.setFirstName((String) user.getFIRSTNAME()); application.setLastName((String) user.getLASTNAME()); application.setMail((String) user.getMAIL()); for (int i = 0; i < files.length; i++) { MultipartFile file = files[i]; System.out.println("Taille : " + file.getSize()); try { byte[] bytes = file.getBytes(); file.getInputStream().read(bytes); System.out.println("URL retourne : " + BusControl.uploadCV(bytes)); if (i == 0) application.setCvPath(BusControl.uploadCV(bytes)); if (i == 1) application.setClPath(BusControl.uploadCV(bytes)); } catch (Exception e) { }/* www.j a v a2 s . c o m*/ } //Ajouter une application la BD Entreprise int applicationID = BusControl.addNewApplicant(application); //Ajouter une application la BD BusControl.createApplication(idUser, 3, applicationID, 0); //mise jour de la liste de candidature APPLICATIONTYPE listCand = getApplications(idUser); ArrayList<Applications> listCan = new ArrayList<>(); if (listCand != null) { Iterator<APPLICATION> ite = listCand.getAPPLICATIONS().iterator(); while (ite.hasNext()) { APPLICATION offer = ite.next(); InternshipCompanyModel inte = BusControl .getOffersById(BusControl.getAppById(offer.getApplicationID()).getInternshipID()); int statusId = BusControl.getAppById(offer.getApplicationID()).getStatus(); String status = Utils.getStatus(statusId); COMPANYTYPE com = BusControl.getCompanybyId(offer.getCompanyID()); Applications can = new Applications(offer.getApplicationID(), null, inte, com.getNOM(), com.getMAIL(), com.getADDRESS(), status); if (statusId != 4) { listCan.add(can); } } } else { listCan = null; } model.addAttribute("listCan", listCan); Utils.drawHomePage(session.getAttribute("userName").toString(), BusControl.getNotifications(idUser).getNOTIFS().size(), "searchStudent", "candidatureStudent", model); return "home"; } else { model.addAttribute("errormessage", " You need to be authenticated. "); return "connection"; } }
From source file:data.repository.pragma.DataObjectController.java
@RequestMapping("/DO/update/data") @ResponseBody//from w ww. j a va 2 s . c o m public MessageResponse setData(@RequestParam(value = "ID", required = true) String id, @RequestParam(value = "data", required = true) MultipartFile file) { // Connect to MongoDB and set metadata as curation purposes // Return a new document ID try { // Get original Grid FS file GridFSDBFile doc = Staging_repository.findDOByID(id); // Ingest multipart file into inputstream byte[] byteArr = file.getBytes(); InputStream inputStream = new ByteArrayInputStream(byteArr); String file_name = file.getOriginalFilename(); String content_type = file.getContentType(); // Push back updated DO to MongoDB and get a new doc ID String updated_id = Staging_repository.addDO(inputStream, file_name, content_type, doc.getMetaData()); MessageResponse response = new MessageResponse(true, updated_id); return response; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); MessageResponse response = new MessageResponse(false, null); return response; } }
From source file:org.aksw.gerbil.web.FileUploadController.java
@RequestMapping(value = "upload", method = RequestMethod.POST) public @ResponseBody ResponseEntity<UploadFileContainer> upload(MultipartHttpServletRequest request, HttpServletResponse response) {/*ww w.j a v a 2s . c o m*/ if (path == null) { logger.error("Path must be not null"); return new ResponseEntity<UploadFileContainer>(HttpStatus.INTERNAL_SERVER_ERROR); } LinkedList<FileMeta> files = new LinkedList<FileMeta>(); MultipartFile mpf = null; for (Iterator<String> it = request.getFileNames(); it.hasNext();) { mpf = request.getFile(it.next()); logger.debug("{} uploaded", mpf.getOriginalFilename()); FileMeta fileContainer = new FileMeta(); fileContainer.setName(mpf.getOriginalFilename()); fileContainer.setSize(mpf.getSize() / 1024 + "Kb"); fileContainer.setFileType(mpf.getContentType()); try { fileContainer.setBytes(mpf.getBytes()); createFolderIfNotExists(); FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream(path + mpf.getOriginalFilename())); } catch (IOException e) { logger.error("Error during file upload", e); fileContainer.setError(e.getMessage()); } files.add(fileContainer); } UploadFileContainer uploadFileContainer = new UploadFileContainer(files); return new ResponseEntity<UploadFileContainer>(uploadFileContainer, HttpStatus.OK); }
From source file:cn.leancloud.diamond.server.controller.AdminController.java
private String getContentFromFile(MultipartFile contentFile) { try {// w w w . j a v a 2 s. c o m String charset = Constants.ENCODE; final String content = new String(contentFile.getBytes(), charset); return content; } catch (Exception e) { throw new ConfigServiceException(e); } }
From source file:org.openbaton.marketplace.api.RestVNFPackage.java
private VNFPackageMetadata onboard(MultipartFile vnfPackage) throws IOException, VimException, NotFoundException, SQLException, PluginException, ImageRepositoryNotEnabled, NoSuchAlgorithmException, ArchiveException, SDKException, NumberOfImageExceededException, AlreadyExistingException, PackageIntegrityException, FailedToUploadException { log.debug("onboard...."); if (!vnfPackage.isEmpty()) { byte[] bytes = vnfPackage.getBytes(); String fileName = vnfPackage.getOriginalFilename(); VNFPackageMetadata vnfPackageMetadata = vnfPackageManagement.add(fileName, bytes, false); return vnfPackageMetadata; } else {// w ww .j a v a 2 s . c o m throw new IOException("File is an empty file!"); } }