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

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

Introduction

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

Prototype

@Nullable
String getContentType();

Source Link

Document

Return the content type of the file.

Usage

From source file:maku.mvc.services.ImageService.java

public static boolean isJpeg(MultipartFile file) {
    return file.getContentType().equals("image/jpeg");
}

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

private static void validateFile(MultipartFile file) throws IOException {
    String contentType = file.getContentType();
    if (!contentType.equals(MediaType.IMAGE_JPEG.toString())
            && !contentType.equals(MediaType.IMAGE_PNG.toString()))
        throw new IOException("Invalid media type");
}

From source file:ru.langboost.controllers.file.FileHelper.java

private static String generateContentType(MultipartFile multipartFile) {
    //        if(multipartFile.getContentType().equals(STREAM_IMAGE_TYPE)) {
    //            return  File.DEFAULT_IMAGE_CONTENT_TYPE;
    //        } else {
    return multipartFile.getContentType();
    //        }//w  w w  .j  a  v a2s .  c o  m
}

From source file:ee.sk.hwcrypto.demo.model.FileWrapper.java

public static FileWrapper create(MultipartFile multipartFile) throws IOException {
    FileWrapper file = new FileWrapper();
    file.setBytes(multipartFile.getBytes());
    file.setFileName(multipartFile.getOriginalFilename());
    file.setMimeType(multipartFile.getContentType());
    return file;/*from ww  w  .j ava2s.c  o m*/
}

From source file:business.Reciept.java

private static model.Image createImage(MultipartFile multiPartFile) throws Exception {

    byte[] byteArray = multiPartFile.getBytes();
    BufferedImage image = ImageIO.read(multiPartFile.getInputStream());
    int height = image.getHeight();
    int width = image.getWidth();

    return new model.Image(byteArray, multiPartFile.getContentType(), height, width);

}

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

public static byte[] createThumbnail(MultipartFile file, int targetSize) throws IOException {
    validateFile(file);/*from www .  j a va 2  s .co m*/

    final BufferedImage image = convertToImage(file);
    final BufferedImage thumb = pad(resize(image, Method.SPEED, targetSize, OP_ANTIALIAS, OP_BRIGHTER), 2);

    return convertToArray(thumb, file.getContentType());
}

From source file:org.grails.plugin.google.drive.GoogleDrive.java

static File insertFile(Drive drive, File metaData, String type, MultipartFile media) throws IOException {
    if (media == null) {
        throw new IllegalArgumentException("Media can't be null");
    }//  w w w.j ava 2  s  .  c  o  m

    type = type != null ? type : media.getContentType();

    ByteArrayContent mediaContent = new ByteArrayContent(type, media.getBytes());

    Drive.Files.Insert request = drive.files().insert(metaData, mediaContent);
    request.getMediaHttpUploader().setProgressListener(new ProgressListener());
    return request.execute();
}

From source file:com.asual.summer.sample.convert.MultipartFileToImageConverter.java

@Override
public Image convert(MultipartFile source) {
    if (source.getSize() != 0 && mimeTypes.contains(source.getContentType())) {
        try {/*  w  w w  . j a  v a 2s  .co  m*/
            return new Image(source);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}

From source file:feign.form.feign.spring.MultipartSupportService.java

@Override
public String upload3(MultipartFile file, String folder, String message) {
    return file.getOriginalFilename() + ":" + file.getContentType();
}

From source file:software.uncharted.rest.ImageResource.java

@RequestMapping(value = "/histogram", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ImageHistogramResponse getImageHistogram(@RequestParam("image") final MultipartFile file)
        throws IOException {
    String fileType = file.getContentType();
    if (fileType.startsWith("image")) {
        BufferedImage image = ImageIO.read(file.getInputStream());
        final String histogram = service.getHistogram(image);
        final String base64Str = ImageProcessing.toBase64(image);
        return new ImageHistogramResponse().setDataURI("data:image/png;base64," + base64Str)
                .setHistogram(histogram);
    }//from  w ww. j  a  v a  2s.c om
    return null;
}