List of usage examples for org.springframework.web.multipart MultipartFile getBytes
byte[] getBytes() throws IOException;
From source file:org.jasig.portlet.attachment.mvc.LocalAttachmentController.java
@RequestMapping(value = "/content/attach/local", method = RequestMethod.POST, produces = "text/plain") public ModelAndView cKEditorUpload(@RequestParam(value = "upload") MultipartFile file, @RequestParam(value = "CKEditorFuncNum") String functionNumber, HttpServletRequest servletRequest) throws IOException { final Map<String, Object> model = new HashMap<String, Object>(); final String user = (String) servletRequest.getSession() .getAttribute(AttachmentsController.REMOTE_USER_ATTR); final HttpServletRequest request = new AttachmentServletRequestWrapper(servletRequest, user); if (file != null) { Attachment attachment = generateAttachment(file, request); attachment = attachmentService.save(attachment, request.getRemoteUser()); if (attachment.getId() > 0) { String path = getAttachmentAbsolutePath(attachment, request); FileUtil.write(path, file.getBytes()); model.put("functionNumber", functionNumber); model.put("attachment", attachment); } else {//from w ww. j a v a 2 s . co m throw new RuntimeException("Failure to upload attachment: " + attachment.getFilename()); } } return new ModelAndView("ckeditor-callback", model); }
From source file:org.jasig.portlet.attachment.mvc.LocalAttachmentController.java
private static Attachment generateAttachment(MultipartFile file, HttpServletRequest req) throws IOException { final Attachment attachment = new Attachment(); final String fileNameParam = req.getParameter("filename"); final String filename = StringUtils.isEmpty(fileNameParam) ? file.getOriginalFilename() : fileNameParam; final String context = req.getContextPath(); final String path = context + PATH_FORMAT.format(new Object[] { attachment.getGuid(), filename }); final String source = req.getParameter("source"); attachment.setFilename(filename);/* www. j a v a2 s. co m*/ attachment.setPath(path); attachment.setData(file.getBytes()); attachment.setSource(StringUtils.isBlank(source) ? null : source); return attachment; }
From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java
private FileSystemResource getResource(MultipartFile multipartFile) throws IOException { String resourcePath = tempDir + "/" + multipartFile.getName(); File file = new File(resourcePath); FileUtils.writeByteArrayToFile(file, multipartFile.getBytes()); return new FileSystemResource(file.getAbsolutePath()); }
From source file:org.jgrades.rest.lic.LicenceManagerService.java
@Override @RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Licence uploadAndInstall(@RequestParam("licence") MultipartFile licence, @RequestParam("signature") MultipartFile signature) throws IOException { LOGGER.info("Licence installation service invoked"); checkFilesExisting(licence, signature); filesNameResolver.init();/*from w ww . ja va 2s . c o m*/ File licenceFile = filesNameResolver.getLicenceFile(); File signatureFile = filesNameResolver.getSignatureFile(); String licenceFilePath = licenceFile.getAbsolutePath(); String signatureFilePath = signatureFile.getAbsolutePath(); LOGGER.info("Saving received licence file to {}", licenceFilePath); FileUtils.writeByteArrayToFile(licenceFile, licence.getBytes()); LOGGER.info("Saving received signature file to {}", signatureFilePath); FileUtils.writeByteArrayToFile(signatureFile, signature.getBytes()); try { return licenceManagingService.installLicence(licenceFilePath, signatureFilePath); } catch (LicenceException ex) { LOGGER.error("Problem during installation licence: {} and signature: {}", licenceFilePath, signatureFilePath, ex); LOGGER.error("Due to exception during installation saved file will be removed: {} , {}", licenceFilePath, signatureFilePath); FileUtils.deleteQuietly(licenceFile); FileUtils.deleteQuietly(signatureFile); throw ex; } }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@RequestMapping(value = "/console/app/import/submit", method = RequestMethod.POST) public String consoleAppImportSubmit(ModelMap map) throws IOException { Collection<String> errors = new ArrayList<String>(); MultipartFile appZip = null; try {/* w w w. j a v a 2 s . c o m*/ appZip = FileStore.getFile("appZip"); } catch (FileLimitException e) { errors.add(ResourceBundleUtil.getMessage("general.error.fileSizeTooLarge", new Object[] { FileStore.getFileSizeLimit() })); } AppDefinition appDef = null; try { if (appZip != null) { appDef = appService.importApp(appZip.getBytes()); } } catch (ImportAppException e) { errors.add(e.getMessage()); } if (appDef == null || !errors.isEmpty()) { map.addAttribute("error", true); map.addAttribute("errorList", errors); return "console/apps/import"; } else { String appId = appDef.getAppId(); String contextPath = WorkflowUtil.getHttpServletRequest().getContextPath(); String url = contextPath + "/web/console/app/" + appId + "/forms"; map.addAttribute("url", url); map.addAttribute("appId", appId); map.addAttribute("appVersion", appDef.getVersion()); map.addAttribute("isPublished", appDef.isPublished()); return "console/apps/packageUploadSuccess"; } }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@RequestMapping(value = "/json/console/app/(*:appId)/(~:version)/package/deploy", method = RequestMethod.POST) public void consolePackageDeploy(Writer writer, @RequestParam(value = "appId") String appId, @RequestParam(value = "version", required = false) String version, HttpServletRequest request) throws JSONException, IOException { String error = null;/*from ww w .j a v a 2 s . c o m*/ appService.getAppDefinition(appId, version); MultipartFile packageXpdl = null; try { packageXpdl = FileStore.getFile("packageXpdl"); } catch (FileLimitException e) { error = ResourceBundleUtil.getMessage("general.error.fileSizeTooLarge", new Object[] { FileStore.getFileSizeLimit() }); } JSONObject jsonObject = new JSONObject(); // TODO: authenticate user boolean authenticated = !workflowUserManager.isCurrentUserAnonymous(); if (authenticated) { if (error == null) { try { // deploy package appService.deployWorkflowPackage(appId, version, packageXpdl.getBytes(), true); jsonObject.accumulate("status", "complete"); } catch (Exception e) { jsonObject.accumulate("errorMsg", e.getMessage().replace(":", "")); } } else { jsonObject.accumulate("errorMsg", error); } } else { jsonObject.accumulate("errorMsg", "unauthenticated"); } AppUtil.writeJson(writer, jsonObject, null); }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@RequestMapping(value = "/console/app/(*:appId)/(~:version)/package/upload/submit", method = RequestMethod.POST) public String consolePackageUploadSubmit(ModelMap map, @RequestParam(value = "appId") String appId, @RequestParam(value = "version", required = false) String version, HttpServletRequest request) { AppDefinition appDef = appService.getAppDefinition(appId, version); map.addAttribute("appId", appId); map.addAttribute("appVersion", appDef.getVersion()); map.addAttribute("appDefinition", appDef); MultipartFile packageXpdl; try {// w ww. j av a2 s. c o m packageXpdl = FileStore.getFile("packageXpdl"); } catch (FileLimitException e) { map.addAttribute("errorMessage", ResourceBundleUtil.getMessage("general.error.fileSizeTooLarge", new Object[] { FileStore.getFileSizeLimit() })); return "console/apps/packageUpload"; } try { if (packageXpdl == null || packageXpdl.isEmpty()) { throw new RuntimeException("Package XPDL is empty"); } appService.deployWorkflowPackage(appId, version, packageXpdl.getBytes(), false); } catch (Throwable e) { map.addAttribute("errorMessage", e.getMessage()); return "console/apps/packageUpload"; } return "console/apps/xpdlUploadSuccess"; }
From source file:org.joget.apps.app.controller.ConsoleWebController.java
@RequestMapping(value = "/desktop/app/import/submit", method = RequestMethod.POST) public String desktopAppImportSubmit(ModelMap map) throws IOException { Collection<String> errors = new ArrayList<String>(); MultipartFile appZip = null; try {/*from www. j a v a 2 s .c om*/ appZip = FileStore.getFile("appZip"); } catch (FileLimitException e) { errors.add(ResourceBundleUtil.getMessage("general.error.fileSizeTooLarge", new Object[] { FileStore.getFileSizeLimit() })); } AppDefinition appDef = null; if (appZip != null) { appDef = appService.importApp(appZip.getBytes()); } if (appDef == null || !errors.isEmpty()) { map.addAttribute("error", true); map.addAttribute("errorList", errors); return "desktop/apps/import"; } else { String appId = appDef.getAppId(); String contextPath = WorkflowUtil.getHttpServletRequest().getContextPath(); String url = contextPath + "/web/console/app/" + appId + "/forms"; map.addAttribute("url", url); map.addAttribute("appId", appId); map.addAttribute("appVersion", appDef.getVersion()); map.addAttribute("isPublished", appDef.isPublished()); return "desktop/apps/packageUploadSuccess"; } }
From source file:org.jumpmind.symmetric.web.rest.RestService.java
private void loadProfileImpl(ISymmetricEngine engine, MultipartFile file) { IDataLoaderService dataLoaderService = engine.getDataLoaderService(); boolean inError = false; try {// ww w.j a va2 s. c o m String content = new String(file.getBytes()); List<IncomingBatch> batches = dataLoaderService.loadDataBatch(content); for (IncomingBatch batch : batches) { if (batch.getStatus() == Status.ER) { inError = true; } } } catch (Exception e) { inError = true; } if (inError) { throw new InternalServerErrorException(); } }
From source file:org.kaaproject.kaa.server.admin.controller.KaaAdminController.java
/** * Gets the file content.//w w w . j a v a 2s . c o m * * @param file * the file * @return the file content * @throws KaaAdminServiceException * the kaa admin service exception */ private byte[] getFileContent(MultipartFile file) throws KaaAdminServiceException { if (!file.isEmpty()) { LOG.debug("Uploading file with name '{}'", file.getOriginalFilename()); try { return file.getBytes(); } catch (IOException e) { throw Utils.handleException(e); } } else { LOG.error("No file found in post request!"); throw new KaaAdminServiceException("No file found in post request!", ServiceErrorCode.FILE_NOT_FOUND); } }