List of usage examples for org.springframework.web.multipart MultipartFile getOriginalFilename
@Nullable String getOriginalFilename();
From source file:org.openmrs.module.patientsummary.web.controller.PatientSummaryTemplateEditor.java
@RequestMapping(method = RequestMethod.POST) public String saveTemplate(String templateUuid, String name, Class<? extends ReportRenderer> rendererType, String properties, String script, String scriptType, boolean enableOnPatientDashboard, HttpServletRequest request, ModelMap model) throws IOException { PatientSummaryTemplate template = getService().getPatientSummaryTemplateByUuid(templateUuid); PatientSummaryWebConfiguration.saveEnableTemplateOnPatientDashboard(template, enableOnPatientDashboard); template.getReportDesign().setName(name); template.getReportDesign().setRendererType(rendererType); if (!template.getReportDesign().getRendererType().equals(TextTemplateRenderer.class)) { MultipartHttpServletRequest mpr = (MultipartHttpServletRequest) request; Map<String, MultipartFile> files = mpr.getFileMap(); MultipartFile resource = files.values().iterator().next(); if (resource != null && !resource.isEmpty()) { ReportDesignResource designResource = new ReportDesignResource(); designResource.setReportDesign(template.getReportDesign()); designResource.setContents(resource.getBytes()); designResource.setContentType(resource.getContentType()); String fileName = resource.getOriginalFilename(); int index = fileName.lastIndexOf("."); designResource.setName(fileName.substring(0, index)); designResource.setExtension(fileName.substring(index + 1)); template.getReportDesign().addResource(designResource); }/*from www. j a v a 2s . c o m*/ WidgetHandler propHandler = HandlerUtil.getPreferredHandler(WidgetHandler.class, Properties.class); Properties props = (Properties) propHandler.parse(properties, Properties.class); template.getReportDesign().setProperties(props); } else { template.getReportDesign().getProperties().clear(); template.getReportDesign().getResources().clear(); ReportDesignResource designResource = new ReportDesignResource(); designResource.setReportDesign(template.getReportDesign()); designResource.setName("template"); designResource.setContentType("text/html"); designResource.setContents(script.getBytes("UTF-8")); template.getReportDesign().addResource(designResource); template.getReportDesign().addPropertyValue(TextTemplateRenderer.TEMPLATE_TYPE, scriptType); } getService().savePatientSummaryTemplate(template); model.put("templateUuid", template.getUuid()); return "redirect:" + PatientSummaryWebConstants.MODULE_URL + "editTemplate.form"; }
From source file:com.luna.common.web.controller.KindEditorController.java
/** * ?//from w w w.j av a2 s.co m * dir file image flash media * <p/> * ?? * * { * error : 1 * message : ? * } * <p/> * * { * error:0 * url:?? * title: * } * * @param response * @param request * @param dir * @param file * @return */ @RequestMapping(value = "upload", method = RequestMethod.POST) @ResponseBody public String upload(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "dir", required = false) String dir, @RequestParam(value = "imgFile", required = false) MultipartFile file) { response.setContentType("text/html; charset=UTF-8"); String[] allowedExtension = extractAllowedExtension(dir); try { String url = FileUploadUtils.upload(request, baseDir, file, allowedExtension, maxSize, true); return successResponse(request, file.getOriginalFilename(), url); } catch (IOException e) { log.error("file upload error", e); return errorResponse("upload.server.error"); } catch (InvalidExtensionException.InvalidImageExtensionException e) { return errorResponse("upload.not.allow.image.extension"); } catch (InvalidExtensionException.InvalidFlashExtensionException e) { return errorResponse("upload.not.allow.flash.extension"); } catch (InvalidExtensionException.InvalidMediaExtensionException e) { return errorResponse("upload.not.allow.media.extension"); } catch (InvalidExtensionException e) { return errorResponse("upload.not.allow.extension"); } catch (FileUploadBase.FileSizeLimitExceededException e) { return errorResponse("upload.exceed.maxSize"); } catch (FileNameLengthLimitExceededException e) { return errorResponse("upload.filename.exceed.length"); } }
From source file:com.artivisi.belajar.restful.ui.controller.ApplicationConfigController.java
@RequestMapping("/config/{id}/files") @ResponseBody/*from w ww . java 2 s .c o m*/ public Map<String, String> uploadFiles(@PathVariable String id, @RequestParam String keterangan, @RequestParam MultipartFile cv, @RequestParam MultipartFile foto) throws Exception { ApplicationConfig config = belajarRestfulService.findApplicationConfigById(id); if (config == null) { throw new IllegalStateException(); } Map<String, String> result = new HashMap<String, String>(); logger.info("CV => Content-Type : {}, Filename : {}, Size : {}", new Object[] { cv.getContentType(), cv.getOriginalFilename(), cv.getSize() }); logger.info("Foto => Content-Type : {}, Filename : {}, Size : {}", new Object[] { foto.getContentType(), foto.getOriginalFilename(), foto.getSize() }); File cvTarget = File.createTempFile(cv.getOriginalFilename().split(ESC_CHAR_TITIK)[0], "." + cv.getOriginalFilename().split(ESC_CHAR_TITIK)[1]); File fotoTarget = File.createTempFile(foto.getOriginalFilename().split(ESC_CHAR_TITIK)[0], "." + foto.getOriginalFilename().split(ESC_CHAR_TITIK)[1]); cv.transferTo(cvTarget); foto.transferTo(fotoTarget); logger.info("CV disimpan ke {}", cvTarget.getAbsolutePath()); logger.info("Foto disimpan ke {}", fotoTarget.getAbsolutePath()); if (cv.getSize() == UKURAN_FILE_CV) { result.put("cv", "success"); } else { result.put("cv", "error size"); } if (foto.getSize() == UKURAN_FILE_FOTO) { result.put("foto", "success"); } else { result.put("foto", "error size"); } if ("File Endy".equals(keterangan)) { result.put("keterangan", "success"); } else { result.put("keterangan", "salah content"); } return result; }
From source file:de.metas.ui.web.window.controller.WindowRestController.java
/** * Attaches a file to given root document. * * @param adWindowId/*from w w w. j a va 2s.com*/ * @param documentId * @param file * @throws IOException */ @PostMapping("/{windowId}/{documentId}/attachments") public void attachFile(@PathVariable("windowId") final int adWindowId // , @PathVariable("documentId") final String documentId // , @RequestParam("file") final MultipartFile file // ) throws IOException { userSession.assertLoggedIn(); final String name = file.getOriginalFilename(); final byte[] data = file.getBytes(); final DocumentPath documentPath = DocumentPath.rootDocumentPath(DocumentType.Window, adWindowId, documentId); final Document document = documentCollection.getDocument(documentPath); Services.get(IAttachmentBL.class).createAttachment(document, name, data); }
From source file:net.duckling.ddl.web.api.rest.FileEditController.java
@RequestMapping(value = "/fileShared", method = RequestMethod.POST) public void fileShared(@RequestParam(value = "path", required = false) String path, @RequestParam("file") MultipartFile file, @RequestParam(value = "ifExisted", required = false) String ifExisted, HttpServletRequest request, HttpServletResponse response) throws IOException { String uid = getCurrentUid(request); int tid = getCurrentTid(); path = StringUtils.defaultIfBlank(path, PathName.DELIMITER); LOG.info("file shared start... {uid:" + uid + ",tid:" + tid + ",path:" + path + ",fileName:" + file.getOriginalFilename() + ",ifExisted:" + ifExisted + "}"); Resource parent = folderPathService.getResourceByPath(tid, path); if (parent == null) { LOG.error("path not found. {tid:" + tid + ", path:" + path + "}"); writeError(ErrorMsg.NOT_FOUND, response); return;/*from w ww . j a va 2 s .c om*/ } List<Resource> list = resourceService.getResourceByTitle(tid, parent.getRid(), LynxConstants.TYPE_FILE, file.getOriginalFilename()); if (list.size() > 0 && !IF_EXISTED_UPDATE.equals(ifExisted)) { LOG.error("file existed. {ifExisted:" + ifExisted + ",fileName:" + file.getOriginalFilename() + "}"); writeError(ErrorMsg.EXISTED, response); return; } FileVersion fv = null; try { fv = resourceOperateService.upload(uid, getCurrentTid(), parent.getRid(), file.getOriginalFilename(), file.getSize(), file.getInputStream()); } catch (NoEnoughSpaceException e) { LOG.error("no enough space. {tid:" + tid + ",size:" + file.getSize() + ",fileName:" + file.getOriginalFilename() + "}"); writeError(ErrorMsg.NO_ENOUGH_SPACE, response); return; } ShareResource sr = shareResourceService.get(fv.getRid()); if (sr == null) { sr = createShareResource(fv.getRid(), uid); } else { sr.setLastEditor(uid); sr.setLastEditTime(new Date()); shareResourceService.update(sr); } sr.setTitle(fv.getTitle()); sr.setShareUrl(sr.generateShareUrl(urlGenerator)); LOG.info("file uploaded and shared successfully. {tid:" + tid + ",path:" + path + ",title:" + fv.getTitle() + "}"); JsonUtil.write(response, VoUtil.getShareResourceVo(sr)); }
From source file:fr.treeptik.cloudunit.controller.ApplicationController.java
/** * Deploy a web application// w w w .j a v a 2 s . co m * * @return * @throws IOException * @throws ServiceException * @throws CheckException */ @ResponseBody @RequestMapping(value = "/{applicationName}/deploy", method = RequestMethod.POST, consumes = { "multipart/form-data" }) public JsonResponse deploy(@RequestPart("file") MultipartFile fileUpload, @PathVariable String applicationName, HttpServletRequest request, HttpServletResponse response) throws IOException, ServiceException, CheckException { logger.info("applicationName = " + applicationName + "file = " + fileUpload.getOriginalFilename()); User user = authentificationUtils.getAuthentificatedUser(); Application application = applicationService.findByNameAndUser(user, applicationName); // We must be sure there is no running action before starting new one authentificationUtils.canStartNewAction(user, application, Locale.ENGLISH); applicationManager.deploy(fileUpload, application); logger.info("--DEPLOY APPLICATION WAR ENDED--"); return new HttpOk(); }
From source file:cn.guoyukun.spring.web.controller.KindEditorController.java
/** * ?//ww w . j a va2 s. co m * dir file image flash media * <p/> * ?? * * { * error : 1 * message : ? * } * <p/> * * { * error:0 * url:?? * title: * } * * @param response * @param request * @param dir * @param file * @return */ @RequestMapping(value = "upload", method = RequestMethod.POST) @ResponseBody public String upload(HttpServletResponse response, HttpServletRequest request, @RequestParam(value = "dir", required = false) String dir, @RequestParam(value = "imgFile", required = false) MultipartFile file) { response.setContentType("text/html; charset=UTF-8"); String[] allowedExtension = extractAllowedExtension(dir); try { String url = FileUploadUtils.upload(request, baseDir, file, allowedExtension, maxSize, true); return successResponse(request, file.getOriginalFilename(), url); } catch (IOException e) { LogUtils.logError("file upload error", e); return errorResponse("upload.server.error"); } catch (InvalidExtensionException.InvalidImageExtensionException e) { return errorResponse("upload.not.allow.image.extension"); } catch (InvalidExtensionException.InvalidFlashExtensionException e) { return errorResponse("upload.not.allow.flash.extension"); } catch (InvalidExtensionException.InvalidMediaExtensionException e) { return errorResponse("upload.not.allow.media.extension"); } catch (InvalidExtensionException e) { return errorResponse("upload.not.allow.extension"); } catch (FileUploadBase.FileSizeLimitExceededException e) { return errorResponse("upload.exceed.maxSize"); } catch (FileNameLengthLimitExceededException e) { return errorResponse("upload.filename.exceed.length"); } }
From source file:com.cloud.ops.resource.ResourcePackageController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody/*w w w . ja v a 2 s . co m*/ public ResourcePackage uploadWar(@RequestParam("file") MultipartFile file, @RequestParam("version") String version, @RequestParam("type") String type, @RequestParam("applicationId") String applicationId) { final ResourcePackage resourcePackage = new ResourcePackage(); resourcePackage.setType(ResourcePackageType.valueOf(type)); resourcePackage.setName(version); resourcePackage.setVersion(version); resourcePackage.setApplicationId(applicationId); if (file != null && !file.getOriginalFilename().trim().equals("")) { String uploadPath = PACKAGE_FILE_PATH + File.separator + UUID.randomUUID().toString() + File.separator; String fileName = file.getOriginalFilename(); final String filePath = uploadPath + fileName; resourcePackage.setStatus(ResourcePackageStatus.SAVING); service.create(resourcePackage); new ThreadWithEntity<ResourcePackage>(resourcePackage) { @Override public void run(ResourcePackage entity) { File destination = new File(filePath); try { fileStore.storeFile(file.getInputStream(), filePath); } catch (IOException e) { throw new OpsException("?war?", e); } entity.setWarPath(destination.getAbsolutePath()); entity.setStatus(ResourcePackageStatus.FINISH); service.create(entity); webSocketHandler.sendMsg(PACKAGE_STATUS, entity); } }.start(); } else { throw new OpsException("war?"); } return resourcePackage; }
From source file:com.engine.biomine.BiomineController.java
@ApiOperation( // Populates the "summary" value = "Index biodata (from local)", // Populates the "description" notes = "Add a biodata file to the index") @ApiResponses(value = { @ApiResponse(code = 200, message = "Accepted", response = Boolean.class), @ApiResponse(code = 400, message = "Bad Request", response = BiomineError.class), @ApiResponse(code = 500, message = "Internal Server Error", response = BiomineError.class), @ApiResponse(code = 503, message = "Service Unavailable", response = BiomineError.class) }) @RequestMapping(value = "/indexer/index/biodata/{data}", method = RequestMethod.POST, produces = { APPLICATION_JSON_VALUE })/* w w w. j a v a 2s .co m*/ @ResponseBody @ConfigurationProperties() public ResponseEntity<Boolean> indexData(HttpServletResponse response, @ApiParam(value = "File", required = true) @RequestParam(value = "path", required = true) MultipartFile path, @ApiParam(value = "Collection", required = true) @RequestParam(value = "collection", required = true) String collection) { if (!path.isEmpty()) { if (IOUtil.getINSTANCE().isValidExtension(path.getOriginalFilename())) { logger.info("Start indexing data from path {}", path.getOriginalFilename()); try { File file = new File(path.getOriginalFilename()); file.createNewFile(); deleteFile = false; FileOutputStream output = new FileOutputStream(file); output.write(path.getBytes()); output.close(); indexer.pushData(file, deleteFile, collection); } catch (IOException e) { e.printStackTrace(); } } else logger.info("File extension not valid. Please select a valid file."); } else logger.info("File does not exist. Please select a valid file."); return new ResponseEntity<Boolean>(true, HttpStatus.OK); }
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 {// ww w . java 2 s. c o m throw new IOException("File is an empty file!"); } }