List of usage examples for org.springframework.web.multipart MultipartFile getName
String getName();
From source file:org.flowable.dmn.rest.service.api.repository.DmnDeploymentCollectionResource.java
@ApiOperation(value = "Create a new decision table deployment", nickname = "uploadDecisionTableDeployment", tags = { "Deployment" }, consumes = "multipart/form-data", produces = "application/json", notes = "The request body should contain data of type multipart/form-data. There should be exactly one file in the request, any additional files will be ignored. The deployment name is the name of the file-field passed in. If multiple resources need to be deployed in a single deployment, compress the resources in a zip and make sure the file-name ends with .bar or .zip.\n" + "\n" + "An additional parameter (form-field) can be passed in the request body with name tenantId. The value of this field will be used as the id of the tenant this deployment is done in.") @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the deployment was created."), @ApiResponse(code = 400, message = "Indicates there was no content present in the request body or the content mime-type is not supported for deployment. The status-description contains additional information.") }) @ApiImplicitParams({ @ApiImplicitParam(name = "file", paramType = "form", dataType = "java.io.File") }) @PostMapping(value = "/dmn-repository/deployments", produces = "application/json", consumes = "multipart/form-data") public DmnDeploymentResponse uploadDeployment( @ApiParam(name = "tenantId") @RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) { if (!(request instanceof MultipartHttpServletRequest)) { throw new FlowableIllegalArgumentException("Multipart request is required"); }/*from www .j a v a 2 s .c om*/ if (restApiInterceptor != null) { restApiInterceptor.executeNewDeploymentForTenantId(tenantId); } MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (multipartRequest.getFileMap().size() == 0) { throw new FlowableIllegalArgumentException("Multipart request with file content is required"); } MultipartFile file = multipartRequest.getFileMap().values().iterator().next(); try { DmnDeploymentBuilder deploymentBuilder = dmnRepositoryService.createDeployment(); String fileName = file.getOriginalFilename(); if (StringUtils.isEmpty(fileName) || !DmnResourceUtil.isDmnResource(fileName)) { fileName = file.getName(); } if (DmnResourceUtil.isDmnResource(fileName)) { deploymentBuilder.addInputStream(fileName, file.getInputStream()); } else { throw new FlowableIllegalArgumentException("File must be of type .dmn"); } deploymentBuilder.name(fileName); if (tenantId != null) { deploymentBuilder.tenantId(tenantId); } if (restApiInterceptor != null) { restApiInterceptor.enhanceDeployment(deploymentBuilder); } DmnDeployment deployment = deploymentBuilder.deploy(); response.setStatus(HttpStatus.CREATED.value()); return dmnRestResponseFactory.createDmnDeploymentResponse(deployment); } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } throw new FlowableException(e.getMessage(), e); } }
From source file:org.flowable.form.rest.service.api.repository.FormDeploymentCollectionResource.java
@ApiOperation(value = "Create a new form deployment", tags = { "Form Deployments" }, consumes = "multipart/form-data", produces = "application/json", notes = "The request body should contain data of type multipart/form-data. There should be exactly one file in the request, any additional files will be ignored. The deployment name is the name of the file-field passed in. Make sure the file-name ends with .form or .xml.") @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the form deployment was created."), @ApiResponse(code = 400, message = "Indicates there was no content present in the request body or the content mime-type is not supported for form deployment. The status-description contains additional information.") }) @ApiImplicitParams({ @ApiImplicitParam(name = "file", paramType = "form", dataType = "java.io.File") }) @PostMapping(value = "/form-repository/deployments", produces = "application/json", consumes = "multipart/form-data") public FormDeploymentResponse uploadDeployment( @ApiParam(name = "tenantId") @RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) { if (!(request instanceof MultipartHttpServletRequest)) { throw new FlowableIllegalArgumentException("Multipart request is required"); }//from w w w. j ava2 s . c o m if (restApiInterceptor != null) { restApiInterceptor.executeNewDeploymentForTenantId(tenantId); } MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (multipartRequest.getFileMap().size() == 0) { throw new FlowableIllegalArgumentException("Multipart request with file content is required"); } MultipartFile file = multipartRequest.getFileMap().values().iterator().next(); try { FormDeploymentBuilder deploymentBuilder = formRepositoryService.createDeployment(); String fileName = file.getOriginalFilename(); if (StringUtils.isEmpty(fileName) || !fileName.endsWith(".form")) { fileName = file.getName(); } if (fileName.endsWith(".form")) { deploymentBuilder.addInputStream(fileName, file.getInputStream()); } else { throw new FlowableIllegalArgumentException("File must be of type .xml or .form"); } deploymentBuilder.name(fileName); if (tenantId != null) { deploymentBuilder.tenantId(tenantId); } if (restApiInterceptor != null) { restApiInterceptor.enhanceDeployment(deploymentBuilder); } FormDeployment deployment = deploymentBuilder.deploy(); response.setStatus(HttpStatus.CREATED.value()); return formRestResponseFactory.createFormDeploymentResponse(deployment); } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } throw new FlowableException(e.getMessage(), e); } }
From source file:org.flowable.rest.dmn.service.api.repository.DmnDeploymentCollectionResource.java
@RequestMapping(value = "/dmn-repository/deployments", method = RequestMethod.POST, produces = "application/json") public DmnDeploymentResponse uploadDeployment( @RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {/*w w w. j av a 2 s.c om*/ if (request instanceof MultipartHttpServletRequest == false) { throw new FlowableIllegalArgumentException("Multipart request is required"); } MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (multipartRequest.getFileMap().size() == 0) { throw new FlowableIllegalArgumentException("Multipart request with file content is required"); } MultipartFile file = multipartRequest.getFileMap().values().iterator().next(); try { DmnDeploymentBuilder deploymentBuilder = dmnRepositoryService.createDeployment(); String fileName = file.getOriginalFilename(); if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".dmn") || fileName.endsWith(".xml"))) { fileName = file.getName(); } if (fileName.endsWith(".dmn") || fileName.endsWith(".xml")) { deploymentBuilder.addInputStream(fileName, file.getInputStream()); } else { throw new FlowableIllegalArgumentException("File must be of type .xml or .dmn"); } deploymentBuilder.name(fileName); if (tenantId != null) { deploymentBuilder.tenantId(tenantId); } DmnDeployment deployment = deploymentBuilder.deploy(); response.setStatus(HttpStatus.CREATED.value()); return dmnRestResponseFactory.createDmnDeploymentResponse(deployment); } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } throw new FlowableException(e.getMessage(), e); } }
From source file:org.flowable.rest.form.service.api.repository.FormDeploymentCollectionResource.java
@RequestMapping(value = "/form-repository/deployments", method = RequestMethod.POST, produces = "application/json") public FormDeploymentResponse uploadDeployment( @RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {/*from w w w. ja va 2s. c o m*/ if (request instanceof MultipartHttpServletRequest == false) { throw new FlowableIllegalArgumentException("Multipart request is required"); } MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (multipartRequest.getFileMap().size() == 0) { throw new FlowableIllegalArgumentException("Multipart request with file content is required"); } MultipartFile file = multipartRequest.getFileMap().values().iterator().next(); try { FormDeploymentBuilder deploymentBuilder = formRepositoryService.createDeployment(); String fileName = file.getOriginalFilename(); if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".form") || fileName.endsWith(".xml"))) { fileName = file.getName(); } if (fileName.endsWith(".form") || fileName.endsWith(".xml")) { deploymentBuilder.addInputStream(fileName, file.getInputStream()); } else { throw new FlowableIllegalArgumentException("File must be of type .xml or .form"); } deploymentBuilder.name(fileName); if (tenantId != null) { deploymentBuilder.tenantId(tenantId); } FormDeployment deployment = deploymentBuilder.deploy(); response.setStatus(HttpStatus.CREATED.value()); return formRestResponseFactory.createFormDeploymentResponse(deployment); } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } throw new FlowableException(e.getMessage(), e); } }
From source file:org.flowable.rest.service.api.repository.DeploymentCollectionResource.java
@ApiOperation(value = "Create a new deployment", tags = { "Deployment" }, consumes = "multipart/form-data", produces = "application/json", notes = "The request body should contain data of type multipart/form-data. There should be exactly one file in the request, any additional files will be ignored. The deployment name is the name of the file-field passed in. If multiple resources need to be deployed in a single deployment, compress the resources in a zip and make sure the file-name ends with .bar or .zip.\n" + "\n" + "An additional parameter (form-field) can be passed in the request body with name tenantId. The value of this field will be used as the id of the tenant this deployment is done in.") @ApiResponses(value = { @ApiResponse(code = 200, message = "Indicates the deployment was created."), @ApiResponse(code = 400, message = "Indicates there was no content present in the request body or the content mime-type is not supported for deployment. The status-description contains additional information.") }) @RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json") public DeploymentResponse uploadDeployment( @ApiParam(name = "deploymentKey") @RequestParam(value = "deploymentKey", required = false) String deploymentKey, @ApiParam(name = "deploymentName") @RequestParam(value = "deploymentName", required = false) String deploymentName, @ApiParam(name = "tenantId") @RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) { if (request instanceof MultipartHttpServletRequest == false) { throw new FlowableIllegalArgumentException("Multipart request is required"); }/* w ww . j av a 2 s .com*/ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (multipartRequest.getFileMap().size() == 0) { throw new FlowableIllegalArgumentException("Multipart request with file content is required"); } MultipartFile file = multipartRequest.getFileMap().values().iterator().next(); try { DeploymentBuilder deploymentBuilder = repositoryService.createDeployment(); String fileName = file.getOriginalFilename(); if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) { fileName = file.getName(); } if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) { deploymentBuilder.addInputStream(fileName, file.getInputStream()); } else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) { deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream())); } else { throw new FlowableIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip"); } if (StringUtils.isEmpty(deploymentName)) { String fileNameWithoutExtension = fileName.split("\\.")[0]; if (StringUtils.isNotEmpty(fileNameWithoutExtension)) { fileName = fileNameWithoutExtension; } deploymentBuilder.name(fileName); } else { deploymentBuilder.name(deploymentName); } if (deploymentKey != null) { deploymentBuilder.key(deploymentKey); } if (tenantId != null) { deploymentBuilder.tenantId(tenantId); } Deployment deployment = deploymentBuilder.deploy(); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createDeploymentResponse(deployment); } catch (Exception e) { if (e instanceof FlowableException) { throw (FlowableException) e; } throw new FlowableException(e.getMessage(), e); } }
From source file:org.flowable.ui.task.rest.runtime.AbstractRelatedContentResource.java
protected ContentItemRepresentation uploadFile(User user, MultipartFile file, String taskId, String processInstanceId, String caseId) { if (file != null && file.getName() != null) { try {// ww w . j a v a 2 s. c o m String contentType = file.getContentType(); // temp additional content type check for IE9 flash uploads if (StringUtils.equals(file.getContentType(), "application/octet-stream")) { contentType = getContentTypeForFileExtension(file); } ContentItem contentItem = contentService.newContentItem(); contentItem.setName(getFileName(file)); contentItem.setProcessInstanceId(processInstanceId); contentItem.setTaskId(taskId); if (StringUtils.isNotEmpty(caseId)) { contentItem.setScopeType("cmmn"); contentItem.setScopeId(caseId); } contentItem.setMimeType(contentType); contentItem.setCreatedBy(user.getId()); contentItem.setLastModifiedBy(user.getId()); contentService.saveContentItem(contentItem, file.getInputStream()); return createContentItemResponse(contentItem); } catch (IOException e) { throw new BadRequestException("Error while reading file data", e); } } else { throw new BadRequestException("File to upload is missing"); } }
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.kuali.rice.krad.web.service.impl.FileControllerServiceImpl.java
/** * {@inheritDoc}/*from w ww .j a v a2 s. c o m*/ */ @Override public ModelAndView addFileUploadLine(final UifFormBase form) { form.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATECOMPONENT.getKey()); form.setAjaxRequest(true); MultipartHttpServletRequest request = (MultipartHttpServletRequest) form.getRequest(); final String collectionId = request.getParameter(UifParameters.UPDATE_COMPONENT_ID); final String bindingPath = request.getParameter(UifConstants.PostMetadata.BINDING_PATH); Class<?> collectionObjectClass = (Class<?>) form.getViewPostMetadata().getComponentPostData(collectionId, UifConstants.PostMetadata.COLL_OBJECT_CLASS); Iterator<String> fileNamesItr = request.getFileNames(); while (fileNamesItr.hasNext()) { String propertyPath = fileNamesItr.next(); MultipartFile uploadedFile = request.getFile(propertyPath); final FileMeta fileObject = (FileMeta) KRADUtils.createNewObjectFromClass(collectionObjectClass); try { fileObject.init(uploadedFile); } catch (Exception e) { throw new RuntimeException("Unable to initialize new file object", e); } String id = UUID.randomUUID().toString() + "_" + uploadedFile.getName(); fileObject.setId(id); fileObject.setDateUploaded(new Date()); fileObject.setUrl("?methodToCall=getFileFromLine&formKey=" + form.getFormKey() + "&fileName=" + fileObject.getName() + "&propertyPath=" + propertyPath); ViewLifecycle.encapsulateLifecycle(form.getView(), form, form.getViewPostMetadata(), null, request, new Runnable() { @Override public void run() { ViewLifecycle.getHelper().processAndAddLineObject(form, fileObject, collectionId, bindingPath); } }); } return getModelAndViewService().getModelAndView(form); }
From source file:org.nishkarma.petclinic.controller.MailController.java
@RequestMapping(value = "/mail/sendMailWithInlineImage", method = RequestMethod.POST) public String sendMailWithInline(@RequestParam("recipientName") final String recipientName, @RequestParam("recipientEmail") final String recipientEmail, @RequestParam("image") final MultipartFile image, final Locale locale) throws MessagingException, IOException { logger.debug("recipientName=" + recipientName); logger.debug("recipientEmail=" + recipientEmail); try {/*from ww w . ja va2s . co m*/ this.emailService.sendMailWithInline(recipientName, recipientEmail, image.getName(), image.getBytes(), image.getContentType(), locale); } catch (Exception e) { logger.error(ExceptionUtils.getStackTrace(e)); throw new NishkarmaException( NishkarmaMessageSource.getMessage("exception_message", NishkarmaLocaleUtil.resolveLocale())); } return "redirect:sent"; }
From source file:org.sakaiproject.assignment2.tool.beans.UploadBean.java
private WorkFlowResult processUploadAll(MultipartFile uploadedFile, Assignment2 assign) { if (!AssignmentAuthoringBean.checkCsrf(csrfToken)) return WorkFlowResult.UPLOAD_FAILURE; // you should have already done validation on the file at this point File newFile = null;//from w w w .ja va 2 s. c om try { newFile = File.createTempFile(uploadedFile.getName(), ".zip"); uploadedFile.transferTo(newFile); } catch (IOException ioe) { if (newFile != null) { newFile.delete(); } throw new UploadException(ioe.getMessage(), ioe); } // try to upload this file try { List<Map<String, String>> uploadInfo = uploadAllLogic.uploadAll(uploadOptions, newFile); addUploadMessages(uploadInfo); } catch (UploadException ue) { if (log.isDebugEnabled()) log.debug("UploadException encountered while attempting to UploadAll for assignment: " + assign.getTitle(), ue); messages.addMessage(new TargettedMessage("assignment2.uploadall.error.failure", new Object[] { assign.getTitle() })); return WorkFlowResult.UPLOAD_FAILURE; } finally { if (newFile != null) { newFile.delete(); } } // ASNN-29 This is the end and it uploads all the grades here for zip triggerUploadEvent(assign); return WorkFlowResult.UPLOAD_SUCCESS; }