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

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

Introduction

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

Prototype

@Nullable
String getOriginalFilename();

Source Link

Document

Return the original filename in the client's filesystem.

Usage

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

@RequestMapping(value = "/deploy", method = RequestMethod.POST)
public ModelAndView deploy(HttpServletRequest request, HttpServletResponse response) {
    String archive = request.getParameter("archive");
    if (LogUtils.isDebug()) {
        logger.debug("deploying archive " + archive);
    }//w  w  w.  j a va2s  .  c  om

    MxJbpmProcessDeployer deployer = new MxJbpmProcessDeployer();

    byte[] bytes = null;
    JbpmContext jbpmContext = null;
    try {
        jbpmContext = ProcessContainer.getContainer().createJbpmContext();

        if (jbpmContext != null && jbpmContext.getSession() != null) {
            MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
            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) {
                    ProcessDefinition processDefinition = deployer.deploy(jbpmContext, mFile.getBytes());
                    bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
                    response.setContentType("image/jpeg");
                    response.setHeader("Pragma", "No-cache");
                    response.setHeader("Expires", "-1");
                    response.setHeader("ICache-Control", "no-cache");
                    response.setDateHeader("Expires", 0L);
                    OutputStream out = response.getOutputStream();
                    out.write(bytes);
                    out.flush();
                    out.close();
                    bytes = null;
                    return null;
                }
            }
        }
    } catch (JbpmException ex) {
        if (jbpmContext != null) {
            jbpmContext.setRollbackOnly();
        }
        request.setAttribute("error_code", 9912);
        request.setAttribute("error_message", "");
        return new ModelAndView("/error");
    } catch (IOException ex) {
        if (jbpmContext != null) {
            jbpmContext.setRollbackOnly();
        }
        request.setAttribute("error_code", 9912);
        request.setAttribute("error_message", "");
        return new ModelAndView("/error");
    } finally {
        Context.close(jbpmContext);
        bytes = null;
    }
    return null;
}

From source file:org.pdfgal.pdfgalweb.utils.impl.FileUtilsImpl.java

@Override
public String saveFile(final MultipartFile file) {

    String name = null;// w  w w. ja va  2  s.  co  m

    if (!file.isEmpty()) {
        try {
            final String originalName = file.getOriginalFilename();
            name = this.getAutogeneratedName(originalName);
            final byte[] bytes = file.getBytes();
            final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(name)));
            stream.write(bytes);
            stream.close();
        } catch (final Exception e) {
            name = null;// TODO Incluir no log.
        }
    }

    return name;
}

From source file:cn.cug.laboratory.controller.FileUpload.java

@RequestMapping(value = "/action/file.do", method = { RequestMethod.POST, RequestMethod.GET })
public @ResponseBody String uploadPhoto(@RequestParam MultipartFile uFile, HttpServletRequest request,
        HttpServletResponse response, ModelMap map) {
    System.out.println("Hello");
    try {//from   w ww  . j  av  a2 s.c om
        if (uFile != null && !uFile.isEmpty()) {
            System.out.println("file:" + uFile.getOriginalFilename());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "success";
}

From source file:org.wso2.security.tools.am.webapp.service.DynamicScannerService.java

private void validateRequest(boolean productUploadAsZipFile, MultipartFile zipFile, String wso2ServerHost,
        int wso2ServerPort) throws AutomationManagerWebException {
    if (productUploadAsZipFile) {
        if (zipFile == null || !zipFile.getOriginalFilename().endsWith(".zip")) {
            throw new AutomationManagerWebException("Zip file required");
        }/*from   w w  w  .  j a v a2s.c o m*/
    } else {
        if (wso2ServerHost == null || wso2ServerPort == -1) {
            throw new AutomationManagerWebException("WSO2 host details are missing");
        }
    }
}

From source file:com.insoul.ti.controller.DemandController.java

@RequestMapping("/update/{demandId}")
@Transactional(value = "transactionManager", rollbackFor = Throwable.class)
public ModelAndView update(@PathVariable Long demandId, @Valid DemandRequest request, BindingResult result) {
    Demand demand = demandDAO.get(demandId);
    MultipartFile image = request.getBusinessPlan();
    if (image != null) {
        String fileType = FileUtil.getFileType(image.getOriginalFilename());
        if (StringUtils.isNotBlank(fileType)) {
            String fileName = new StringBuilder().append(UUID.randomUUID()).append(".").append(fileType)
                    .toString();//w ww  . ja  va2  s . co  m
            try {
                String path = CDNUtil.uploadFile(image.getInputStream(), fileName);
                if (StringUtils.isNotBlank(path))
                    demand.setBusinessPlan(path);
            } catch (Exception e) {
                log.error("UploadFile Error.", e);
            }
        }
    }
    demand.setProjectName(request.getProjectName());
    demand.setStatus(request.getStatus());
    demand.setAdvantage(request.getAdvantage());
    demand.setContent(request.getContent());
    demand.setContactPerson(request.getContactPerson());
    demand.setContact(request.getContact());
    demand.setBusinessLicense(request.getBusinessLicense());
    demandDAO.update(demand);
    return new ModelAndView("redirect:/demand/detail/" + demandId);
}

From source file:org.aksw.gerbil.web.FileUploadController.java

@RequestMapping(value = "upload", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<UploadFileContainer> upload(MultipartHttpServletRequest request,
        HttpServletResponse response) {//w w w .j  av a2  s  .  co 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:com.zuoxiaolong.niubi.job.console.controller.StandbyJobController.java

@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ExceptionForward("/standbyJobSummaries")
public String upload(String packagesToScan, @RequestParam MultipartFile jobJar) {
    AssertHelper.notNull(jobJar, "jobJar can't be null.");
    AssertHelper.notEmpty(packagesToScan, "packagesToScan can't be empty.");
    String jarFilePath = getDirectoryRealPath("job/standby") + "/" + jobJar.getOriginalFilename();
    try {//from  w w w  .j a  v  a2 s .  c  o m
        IOHelper.writeFile(jarFilePath, jobJar.getBytes());
        standbyJobService.saveJob(jarFilePath, packagesToScan);
    } catch (IOException e) {
        throw new NiubiException(e);
    }
    return "forward:/standbyJobSummaries";
}

From source file:au.com.gaiaresources.bdrs.service.managedFile.ManagedFileService.java

private ManagedFile saveManagedFile(ManagedFile mf, String description, String credit, String license,
        MultipartFile file) throws IOException {
    mf.setDescription(description);//from  ww  w.ja  v  a2  s  . co m
    mf.setCredit(credit);
    mf.setLicense(license);

    if (file != null) {
        mf.setContentType(file.getContentType());
        mf.setFilename(file.getOriginalFilename());
    } else {
        log.warn("file is null or empty");
    }

    mf = managedFileDAO.saveOrUpdate(mf);

    if (file != null) {
        fileService.createFile(mf, file);
        File f = fileService.getFile(mf, mf.getFilename()).getFile();
        mf.setContentType(FileUtils.getContentType(f));
        mf = managedFileDAO.saveOrUpdate(mf);
    }
    return mf;
}

From source file:com.glaf.jbpm.web.rest.MxJbpmDeployResource.java

@POST
@Path("deploy")
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
@ResponseBody//from   w w  w .  j  av a2s .  c om
public byte[] deploy(@Context HttpServletRequest request) {
    MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    Map<String, Object> paramMap = RequestUtils.getParameterMap(req);
    if (LogUtils.isDebug()) {
        logger.debug(paramMap);
    }
    int status_code = 0;
    String cause = null;
    Map<String, MultipartFile> fileMap = req.getFileMap();
    Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet();
    for (Entry<String, MultipartFile> entry : entrySet) {
        MultipartFile mFile = entry.getValue();
        String filename = mFile.getOriginalFilename();
        long filesize = mFile.getSize();
        if (filename == null || filesize <= 0) {
            continue;
        }
        if (filename.endsWith(".jar") || filename.endsWith(".zip")) {
            JbpmContext jbpmContext = null;
            MxJbpmProcessDeployer deployer = new MxJbpmProcessDeployer();
            try {
                jbpmContext = ProcessContainer.getContainer().createJbpmContext();
                if (jbpmContext != null && jbpmContext.getSession() != null) {
                    deployer.deploy(jbpmContext, mFile.getBytes());
                    status_code = 200;
                }
            } catch (Exception ex) {
                if (jbpmContext != null) {
                    jbpmContext.setRollbackOnly();
                }
                status_code = 500;
                throw new JbpmException(ex);
            } finally {
                com.glaf.jbpm.context.Context.close(jbpmContext);
            }
        }
    }

    Map<String, Object> jsonMap = new java.util.HashMap<String, Object>();
    if (status_code == 200) {
        jsonMap.put("statusCode", 200);
        jsonMap.put("message", "???");
    } else if (status_code == 401) {
        jsonMap.put("statusCode", 401);
        jsonMap.put("message", "????");
    } else if (status_code == 500) {
        jsonMap.put("statusCode", 500);
        jsonMap.put("message", "?????");
        jsonMap.put("cause", cause);
    } else {
        jsonMap.put("statusCode", status_code);
        jsonMap.put("message", "??????");
    }

    JSONObject jsonObject = new JSONObject(jsonMap);

    try {
        return jsonObject.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return jsonObject.toString().getBytes();
    }
}

From source file:org.openmrs.module.filemanager.api.impl.FileManagerServiceImpl.java

public File multipartToFile(MultipartFile multipart) throws IllegalStateException, IOException {
    File tmpFile = new File(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator")
            + multipart.getOriginalFilename());
    multipart.transferTo(tmpFile);/*from  w  w w . j  a  v a 2 s  . c  o  m*/
    return tmpFile;
}