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.vsquaresystem.safedeals.readyreckoner.ReadyReckonerService.java

@Transactional(readOnly = false)
public Boolean insertAttachments(MultipartFile attachmentMultipartFile)
        throws JsonProcessingException, IOException {
    Readyreckoner rr = new Readyreckoner();

    File outputFile = attachmentUtils.storeAttachmentByAttachmentType(
            attachmentMultipartFile.getOriginalFilename(), attachmentMultipartFile.getInputStream(),
            AttachmentUtils.AttachmentType.READY_RECKONER);
    return outputFile.exists();
}

From source file:com.glaf.mail.web.springmvc.MailTaskController.java

@RequestMapping("/uploadMails")
public ModelAndView uploadMails(HttpServletRequest request, ModelMap modelMap) {
    MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    Map<String, Object> params = RequestUtils.getParameterMap(req);
    logger.debug(params);//ww  w  .j  av a 2s  . c o m
    // System.out.println(params);
    String taskId = req.getParameter("taskId");
    if (StringUtils.isEmpty(taskId)) {
        taskId = req.getParameter("id");
    }
    MailTask mailTask = null;
    if (StringUtils.isNotEmpty(taskId)) {
        mailTask = mailTaskService.getMailTask(taskId);
    }

    if (mailTask != null && StringUtils.equals(RequestUtils.getActorId(request), mailTask.getCreateBy())) {

        try {
            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) {
                    logger.debug(mFile.getName());
                    if (mFile.getOriginalFilename().endsWith(".txt")) {
                        byte[] bytes = mFile.getBytes();
                        String rowIds = new String(bytes);
                        List<String> addresses = StringTools.split(rowIds);
                        if (addresses.size() <= 100000) {
                            mailDataFacede.saveMails(taskId, addresses);
                        } else {
                            throw new RuntimeException("mail addresses too many");
                        }
                        break;
                    }
                }
            }
        } catch (Exception ex) {// ?
            ex.printStackTrace();
            throw new RuntimeException(ex.getMessage());
        }
    }
    return this.mailList(request, modelMap);
}

From source file:eionet.transfer.controller.FileOpsController.java

/**
 * AJAX Upload file for transfer./*w w  w  .  ja v  a  2 s.c  o  m*/
 */
@RequestMapping(value = "/fileupload", method = RequestMethod.POST, params = "ajaxupload=1")
public void importFileWithAJAX(@RequestParam("file") MultipartFile myFile, @RequestParam("fileTTL") int fileTTL,
        HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (myFile == null || myFile.getOriginalFilename() == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Select a file to upload");
        return;
    }
    if (fileTTL > 90) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid expiration date");
        return;
    }
    String uuidName = storeFile(myFile, fileTTL);
    response.setContentType("text/xml");
    PrintWriter printer = response.getWriter();
    StringBuffer requestUrl = request.getRequestURL();
    String url = requestUrl.substring(0, requestUrl.length() - "/fileupload".length());
    printer.println("<?xml version='1.0'?>");
    printer.println("<package>");
    printer.println("<downloadLink>" + url + "/download/" + uuidName + "</downloadLink>");
    printer.println("<deleteLink>" + url + "/delete/" + uuidName + "</deleteLink>");
    printer.println("</package>");
    printer.flush();
    response.flushBuffer();
}

From source file:com.appspot.potlachkk.controller.ImageSvc.java

@Multipart
@RequestMapping(value = ImageSvcApi.IMG_SVC_PATH, method = RequestMethod.POST)
public @ResponseBody Long addImage(@RequestParam("imageData") MultipartFile imageFile) throws Exception {

    //TODO here could be some kind of validation to
    // see what kind of data is really uploaded to the 
    // server//  w w  w. j av  a  2s  . c  om
    GiftImage img = new GiftImage();

    img.setMimeType(imageFile.getContentType());
    img.setFilename(imageFile.getOriginalFilename());

    Blob data = new Blob(imageFile.getBytes());

    img.setData(data);

    GiftImage retImg = images.save(img);
    return retImg.getId();
}

From source file:org.hsweb.web.controller.file.FileController.java

/**
 * ,?.???,{@link FileService#saveFile(InputStream, String)}?
 * ??,??:[{"id":"fileId","name":"fileName","md5":"md5"}]
 *
 * @param files /* ww w . j  a va2s  .c om*/
 * @return .
 * @throws IOException ?
 */
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@AccessLogger("")
public ResponseMessage upload(@RequestParam("file") MultipartFile[] files) throws IOException {
    if (logger.isInfoEnabled())
        logger.info(String.format("start upload , file number:%s", files.length));
    List<Resources> resourcesList = new LinkedList<>();
    for (int i = 0; i < files.length; i++) {
        MultipartFile file = files[i];
        if (!file.isEmpty()) {
            if (logger.isInfoEnabled())
                logger.info("start write file:{}", file.getOriginalFilename());
            String fileName = file.getOriginalFilename();
            Resources resources = fileService.saveFile(file.getInputStream(), fileName);
            resourcesList.add(resources);
        }
    } //????
    return ResponseMessage.ok(resourcesList).include(Resources.class, "id", "name", "md5");
}

From source file:com.aboutdata.service.bean.ImageGraphicsServiceImpl.java

@Override
@Deprecated/*  www  .java 2s  .  c  o  m*/
public void build(Photos photos, MultipartFile multipartFile) {
    if (multipartFile != null && !multipartFile.isEmpty()) {
        try {
            File tempFile = new File(
                    System.getProperty("java.io.tmpdir") + "/upload_" + multipartFile.getOriginalFilename());
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            multipartFile.transferTo(tempFile);
            //addTask(sourcePath, largePath, mediumPath, thumbnailPath, tempFile, multipartFile.getContentType());
            String path = storageService.upload(tempFile);

            //?? wallhaven?
            //Random r1 = new Random();
            //int num = r1.nextInt(19) + 1;
            //String thumbnail = "http://themes.mediacreed.com/html/synergy/assets/media/galleries/image_gallery/thumbs/thumb" + num + ".jpg";
            //String medium = "http://themes.mediacreed.com/html/synergy/assets/media/galleries/image_gallery/images/image" + num + ".jpg";
            /**
             * EasyImage??
             */
            EasyImage image = new EasyImage(tempFile);
            float width = image.getWidth();
            //??
            int resize = (int) ((200 / width) * 100);
            image.resize(resize);
            //?
            image.saveAs("/tmp/" + tempFile.getName());
            File tempThumbnail = new File("/tmp/" + tempFile.getName());
            String thumbnail = storageService.upload(tempThumbnail);
            //?
            tempThumbnail.delete();

        } catch (IOException | IllegalStateException e) {
            e.printStackTrace();
        }
    }
}

From source file:pdl.web.controller.web.GenericController.java

@RequestMapping(value = "fileupload", method = RequestMethod.POST)
public String processUpload(@RequestParam("file") MultipartFile file, @RequestParam("type") String type,
        Model model, Principal principal) {

    try {//from ww  w.  ja v a 2  s  .  co  m
        FileService fileService = new FileService();
        fileService.uploadFile(file, type, principal.getName());
    } catch (Exception ex) {

    }

    model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully");

    return "fileupload";
}

From source file:ch.ralscha.extdirectspring_itest.FileUploadService.java

@ExtDirectMethod(value = ExtDirectMethodType.FORM_POST, group = "itest_upload_service", event = "test", entryClass = String.class, synchronizeOnSession = true)
public ExtDirectFormPostResult uploadTest(@RequestParam("fileUpload") MultipartFile file, @Valid User user,
        BindingResult result) throws IOException {

    ExtDirectFormPostResult resp = new ExtDirectFormPostResult(result, false);

    if (file != null && !file.isEmpty()) {
        resp.addResultProperty("fileContents", new String(file.getBytes()));
        resp.addResultProperty("fileName", file.getOriginalFilename());
    }//from  ww  w  .  j a  va  2 s. c o  m

    resp.addResultProperty("name", user.getName());
    resp.addResultProperty("firstName", user.getFirstName());
    resp.addResultProperty("age", user.getAge());
    resp.addResultProperty("e-mail", user.getEmail());

    resp.setSuccess(true);
    return resp;
}

From source file:ch.ralscha.extdirectspring.provider.UploadService.java

@ExtDirectMethod(value = ExtDirectMethodType.FORM_POST, group = "group2", synchronizeOnSession = true)
public ExtDirectFormPostResult upload(@RequestParam("fileUpload") MultipartFile file, @Valid User user,
        BindingResult result) throws IOException {

    ExtDirectFormPostResult resp = new ExtDirectFormPostResult(result, false);

    if (file != null && !file.isEmpty()) {
        resp.addResultProperty("fileContents", new String(file.getBytes()));
        resp.addResultProperty("fileName", file.getOriginalFilename());
    }/*  w  w  w .j a  va 2  s  .  co  m*/

    resp.addResultProperty("name", user.getName());
    resp.addResultProperty("firstName", user.getFirstName());
    resp.addResultProperty("age", user.getAge());
    resp.addResultProperty("e-mail", user.getEmail());

    resp.setSuccess(true);
    return resp;
}

From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.DataFileManagementService.java

public FileParserMessage parse(final MultipartFile multipartFile, final Boolean readFirstColumnAsColumnName) {
    log.debug("parse() - multipartFile: {}, readFirstColumnAsColumnName: {}", multipartFile,
            readFirstColumnAsColumnName);

    final String fileName = multipartFile.getOriginalFilename();
    final DataFileParserService fileDataParserService = fileDataParserServiceFactory
            .getParse(fileName.substring(fileName.lastIndexOf(".")));
    final FileParserMessage<DataFileColumn> result = fileDataParserService.parse(multipartFile,
            readFirstColumnAsColumnName);

    return new FileParserMessage(dataFileColumnToDataFileColumnDtoConverter.convertToList(result.getData()),
            result.getFileParseErrors());
}