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

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

Introduction

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

Prototype

long getSize();

Source Link

Document

Return the size of the file in bytes.

Usage

From source file:com.jayway.restassured.examples.springmvc.controller.FileUploadController.java

@RequestMapping(value = "/fileUpload", method = POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_VALUE)
public @ResponseBody String fileUpload(@RequestParam MultipartFile file) {
    return "{ \"size\" : " + file.getSize() + ", \"name\" : \"" + file.getName() + "\" }";
}

From source file:uk.ac.bbsrc.tgac.browser.web.UploadController.java

private List<MultipartFile> getMultipartFiles(MultipartHttpServletRequest request) {
    List<MultipartFile> files = new ArrayList<MultipartFile>();
    Map<String, MultipartFile> fMap = request.getFileMap();
    for (String fileName : fMap.keySet()) {
        MultipartFile fileItem = fMap.get(fileName);
        if (fileItem.getSize() > 0) {
            files.add(fileItem);//from   w w w . j a v  a2s  .co m
        }
    }
    return files;
}

From source file:com.jayway.restassured.examples.springmvc.controller.FileUploadController.java

@RequestMapping(value = "/fileUpload2", method = POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_VALUE)
public @ResponseBody String fileUpload2(@RequestParam(value = "controlName") MultipartFile file) {
    return "{ \"size\" : " + file.getSize() + ", \"name\" : \"" + file.getName() + "\", \"originalName\" : \""
            + file.getOriginalFilename() + "\", \"mimeType\" : \"" + file.getContentType() + "\" }";
}

From source file:com.chinalbs.service.impl.FileServiceImpl.java

@Override
public String saveImage(MultipartFile[] multipartFile) {
    String webPath = null;//from   w  w w . j a  v  a  2 s. c om
    if (multipartFile == null || multipartFile.length == 0) {
        return null;
    }
    try {
        for (MultipartFile multiFile : multipartFile) {
            if (multiFile.getSize() > ImageMaxSize) {
                continue;
            }
            String uuid = UUID.randomUUID().toString();
            String sourcePath = uploadPath + File.separator + "src_" + uuid + "."
                    + FilenameUtils.getExtension(multiFile.getOriginalFilename());
            //            webPath = uuid + "." + DEST_EXTENSION;
            webPath = File.separator + "src_" + uuid + "."
                    + FilenameUtils.getExtension(multiFile.getOriginalFilename());
            String storePath = uploadPath + File.separator + uuid + "." + DEST_EXTENSION;
            ;

            File tempFile = new File(System.getProperty("java.io.tmpdir") + File.separator + "upload_"
                    + UUID.randomUUID() + ".tmp");
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }

            multiFile.transferTo(tempFile);
            proccessImage(tempFile, sourcePath, storePath, licenseImageWidth, licenseImageHeight, true);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return webPath;
}

From source file:ru.mystamps.web.validation.jsr303.MaxFileSizeValidator.java

@Override
public boolean isValid(MultipartFile file, ConstraintValidatorContext context) {

    if (file == null) {
        return true;
    }//from   w ww  . j  a  va2s.c  om

    return file.getSize() <= maxFileSizeInBytes;
}

From source file:io.restassured.examples.springmvc.controller.FileUploadController.java

@RequestMapping(value = "/fileUploadWithControlNameEqualToSomething", method = POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_VALUE)
public @ResponseBody String fileUploadWithControlNameEqualToSomething(
        @RequestParam(value = "something") MultipartFile file) {
    return "{ \"size\" : " + file.getSize() + ", \"name\" : \"" + file.getName() + "\", \"originalName\" : \""
            + file.getOriginalFilename() + "\", \"mimeType\" : \"" + file.getContentType() + "\" }";
}

From source file:dijalmasilva.controllers.ControladorIdolo.java

@RequestMapping("/new")
public String newIdolo(IdoloForm i, HttpServletRequest req, MultipartFile foto) throws IOException {
    Idolo idolo = convertToIdolo(i);//w w w.j av a  2 s .co  m

    if (foto.getSize() != 0) {
        idolo.setFoto(foto.getBytes());
    }

    Idolo newIdolo = serviceIdolo.salvar(idolo);

    if (newIdolo == null) {
        req.setAttribute("result", "No foi possvel cadastrar dolo.");
    } else {
        req.setAttribute("result", "?dolo cadastrado com sucesso.");
    }

    return "newGroup";
}

From source file:com.trenako.web.images.MultipartFileValidator.java

@Override
public void validate(Object target, Errors errors) {
    // skip validation for empty files.
    if (target == null)
        return;//from   www .j a va2 s .  c  om

    MultipartFile file = (MultipartFile) target;
    if (file.isEmpty())
        return;

    // validate file size
    if (file.getSize() > AppGlobals.MAX_UPLOAD_SIZE) {
        errors.reject("uploadFile.size.range.notmet", "Invalid media size. Max size is 512 Kb");
    }

    // validate content type
    MediaType contentType = MediaType.parseMediaType(file.getContentType());
    if (!AppGlobals.ALLOWED_MEDIA_TYPES.contains(contentType.toString())) {
        errors.reject("uploadFile.contentType.notvalid", "Invalid media type");
    }
}

From source file:no.dusken.aranea.admin.control.EditPersonController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object,
        BindException errors) throws Exception {
    Person person = (Person) object;/*from   w  ww  . j  a  v a2s  . com*/

    // should we upload a new image?
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    MultipartFile file = multipartRequest.getFile("file");
    if (file != null && file.getSize() > 0) {
        Image image = storeImageService.createImage(file);
        image.setCreated(new Date());
        image.setDescription("portrait of " + person.getFirstname() + " " + person.getSurname());
        person.setPortrait(image);
    }

    if (person.getEmailAddress().equals("")) {//default to username@underdusken.no
        person.setEmailAddress(person.getUsername() + "@underdusken.no");
    }
    return super.onSubmit(request, response, person, errors);
}

From source file:com.example.securelogin.app.common.validation.UploadFileMaxSizeValidator.java

@Override
public boolean isValid(MultipartFile multipartFile, ConstraintValidatorContext context) {
    if (constraint.value() < 0 || multipartFile == null) {
        return true;
    }//from w ww .java2 s . c o m
    return multipartFile.getSize() <= constraint.value();
}