Example usage for org.springframework.web.multipart MultipartFile getInputStream

List of usage examples for org.springframework.web.multipart MultipartFile getInputStream

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartFile getInputStream.

Prototype

@Override
InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream to read the contents of the file from.

Usage

From source file:edu.uiowa.icts.bluebutton.controller.LoincCodeCategoryController.java

@RequestMapping(value = "import", method = RequestMethod.POST)
public String importCSV(@RequestParam("file") MultipartFile file) throws IOException {
    this.bluebuttonDaoService.getLoincCodeCategoryService().importCSV(file.getInputStream());
    return "redirect:/loinccodecategory/";
}

From source file:edu.uiowa.icts.bluebutton.controller.LabTestController.java

@RequestMapping(value = "import", method = RequestMethod.POST)
public String importCSV(@RequestParam("file") MultipartFile file) throws IOException {
    this.bluebuttonDaoService.getLabTestService().importCSV(file.getInputStream());
    return "redirect:/labtest/";
}

From source file:net.maritimecloud.identityregistry.controllers.LogoController.java

/**
 * Creates or updates a logo for an organization
 * @param request request to get servletPath
 * @param orgMrn resource location for organization
 * @param logo the log encoded as a MultipartFile
 * @throws McBasicRestException//from   www.  j  a va 2  s  .c o  m
 */
@RequestMapping(value = "/api/org/{orgMrn}/logo", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> createLogoPost(HttpServletRequest request, @PathVariable String orgMrn,
        @RequestParam("logo") MultipartFile logo) throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        try {
            this.updateLogo(org, logo.getInputStream());
            organizationService.save(org);
            return new ResponseEntity<>(HttpStatus.CREATED);
        } catch (IOException e) {
            log.error("Unable to create logo", e);
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_IMAGE,
                    request.getServletPath());
        }
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:de.blizzy.documentr.web.attachment.AttachmentController.java

private void saveAttachmentInternal(String projectName, String branchName, String pagePath, MultipartFile file,
        Authentication authentication) throws IOException {

    log.debug("saving attachment: {}", file.getOriginalFilename()); //$NON-NLS-1$

    byte[] data = IOUtils.toByteArray(file.getInputStream());
    String contentType = servletContext.getMimeType(file.getOriginalFilename());
    if (StringUtils.isBlank(contentType)) {
        contentType = DocumentrConstants.DEFAULT_MIME_TYPE;
    }//  w  ww.  ja  va2 s .  c  om
    Page attachment = Page.fromData(data, contentType);
    pagePath = Util.toRealPagePath(pagePath);
    User user = userStore.getUser(authentication.getName());
    pageStore.saveAttachment(projectName, branchName, pagePath, file.getOriginalFilename(), attachment, user);
}

From source file:org.khmeracademy.btb.auc.pojo.service.impl.UploadImage_serviceimpl.java

@Override
public Image upload(int pro_id, List<MultipartFile> files) {
    Image uploadImage = new Image();
    if (files.isEmpty()) {

    } else {/*  ww  w.j a  v a2  s .  c o  m*/

        //            if(folder=="" || folder==null)
        //                folder = "default";
        String UPLOAD_PATH = "/opt/project/default";
        String THUMBNAIL_PATH = "/opt/project/thumnail/";

        java.io.File path = new java.io.File(UPLOAD_PATH);
        java.io.File thum_path = new java.io.File(THUMBNAIL_PATH);
        if (!path.exists())
            path.mkdirs();
        if (!thum_path.exists()) {
            thum_path.mkdirs();
        }

        List<String> names = new ArrayList<>();
        for (MultipartFile file : files) {
            String fileName = file.getOriginalFilename();
            fileName = UUID.randomUUID() + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
            try {
                byte[] bytes = file.getBytes();
                Files.copy(file.getInputStream(), Paths.get(UPLOAD_PATH, fileName)); //copy path name to server
                try {
                    //TODO: USING THUMBNAILS TO RESIZE THE IMAGE

                    Thumbnails.of(UPLOAD_PATH + "/" + fileName).forceSize(640, 640).toFiles(thum_path,
                            Rename.NO_CHANGE);
                } catch (Exception ex) {
                    BufferedOutputStream stream = new BufferedOutputStream(
                            new FileOutputStream(new File(THUMBNAIL_PATH + fileName)));
                    stream.write(bytes);
                    stream.close();
                }
                names.add(fileName); // add file name
                imRepo.upload(pro_id, fileName); // upload path to database
            } catch (Exception e) {

            }
        }
        uploadImage.setProjectPath("/resources/");
        uploadImage.setServerPath(UPLOAD_PATH);
        uploadImage.setNames(names);
        uploadImage.setMessage("File has been uploaded successfully!!!");
    }
    return uploadImage;
}

From source file:com.fantasia.snakerflow.web.ProcessController.java

/**
 * ??//w w w .j av a  2s.com
 * @param snakerFile
 * @param id
 * @return
 */
@RequestMapping(value = "deploy", method = RequestMethod.POST)
public String processDeploy(@RequestParam(value = "snakerFile") MultipartFile snakerFile, String id) {
    InputStream input = null;
    try {
        input = snakerFile.getInputStream();
        if (StringUtils.isNotEmpty(id)) {
            facets.getEngine().process().redeploy(id, input);
        } else {
            facets.getEngine().process().deploy(input);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return "redirect:/snaker/process/list";
}

From source file:org.magnum.dataup.VideoSvc.java

@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.POST)
public @ResponseBody VideoStatus setVideoData(@PathVariable(ID_PARAMETER) long id,
        @RequestParam(DATA_PARAMETER) MultipartFile videoData, HttpServletResponse response)
        throws IOException {
    VideoFileManager videoDataMgr = VideoFileManager.get();
    Video v = getVideoById(id);//from www. j  ava 2 s.  co  m

    if (v != null) {
        videoDataMgr.saveVideoData(v, videoData.getInputStream());
    } else {
        response.setStatus(404);
    }

    return new VideoStatus(VideoState.READY);
}

From source file:io.lavagna.web.api.SetupController.java

@RequestMapping(value = "/setup/api/import", method = RequestMethod.POST)
public void importLavagna(@RequestParam("file") MultipartFile file, HttpServletRequest req,
        HttpServletResponse res) throws IOException {

    // TODO: move to a helper, as it has the same code as the one in the ExportImportController
    Path tempFile = Files.createTempFile(null, null);
    try {//from   w w  w .j a  v  a2  s  . co m
        try (InputStream is = file.getInputStream(); OutputStream os = Files.newOutputStream(tempFile)) {
            StreamUtils.copy(is, os);
        }
        exportImportService2.importData(true, tempFile);
    } finally {
        Files.delete(tempFile);
    }
    //

    res.sendRedirect(req.getServletContext().getContextPath());
}

From source file:com.glaf.jbpm.web.springmvc.MxJbpmDeployController.java

@RequestMapping(value = "/reconfig", method = RequestMethod.POST)
public ModelAndView reconfig(HttpServletRequest request) {
    String actorId = RequestUtils.getActorId(request);
    String archive = request.getParameter("archive");
    if (LogUtils.isDebug()) {
        logger.debug("deploying archive " + archive);
    }/*from   w ww . j a  v  a2  s .c  o  m*/
    MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    JbpmExtensionReader reader = new JbpmExtensionReader();
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();
        Map<String, MultipartFile> fileMap = req.getFileMap();
        Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet();
        for (Entry<String, MultipartFile> entry : entrySet) {
            MultipartFile mFile = entry.getValue();
            if (mFile.getOriginalFilename() != null && mFile.getSize() > 0) {
                List<Extension> extensions = reader.readTasks(mFile.getInputStream());
                if (extensions != null && extensions.size() > 0) {
                    Iterator<Extension> iter = extensions.iterator();
                    while (iter.hasNext()) {
                        Extension extension = iter.next();
                        extension.setCreateActorId(actorId);
                    }
                    JbpmExtensionManager jbpmExtensionManager = ProcessContainer.getContainer()
                            .getJbpmExtensionManager();
                    jbpmExtensionManager.reconfig(jbpmContext, extensions);
                    request.setAttribute("message", "???");
                }
            }
        }
    } catch (Exception ex) {
        if (jbpmContext != null) {
            jbpmContext.setRollbackOnly();
        }
        request.setAttribute("error_code", 9913);
        request.setAttribute("error_message", "");
        return new ModelAndView("/error");
    } finally {
        Context.close(jbpmContext);
    }

    String jx_view = request.getParameter("jx_view");

    if (StringUtils.isNotEmpty(jx_view)) {
        return new ModelAndView(jx_view);
    }

    String x_view = ViewProperties.getString("jbpm_deploy.configFinish");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view);
    }

    return new ModelAndView("/jbpm/deploy/configFinish");
}

From source file:ru.mystamps.web.service.FilesystemImagePersistenceStrategy.java

protected void writeToFile(MultipartFile file, Path dest) throws IOException {
    // we can't use file.transferTo(dest) there because it creates file
    // relatively to directory from spring.http.multipart.location
    // in application.properties
    // See for details: https://jira.spring.io/browse/SPR-12650
    Files.copy(file.getInputStream(), dest);
}