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

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

Introduction

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

Prototype

byte[] getBytes() throws IOException;

Source Link

Document

Return the contents of the file as an array of bytes.

Usage

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[] convert(MultipartFile file) throws IOException {
    validateFile(file);/*w  ww.  j  av a2 s . com*/
    return file.getBytes();
}

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

private static BufferedImage convertToImage(MultipartFile file) throws IOException {
    InputStream in = new ByteArrayInputStream(file.getBytes());
    return ImageIO.read(in);
}

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 w w  w.  ja v a2  s . c o  m
}

From source file:mx.com.pendulum.carga.util.Md5Converter.java

public static String getMD5Checksum(MultipartFile multipartFile) {
    InputStream is = null;/*from  w w  w  .j  a va 2  s  .  c o  m*/
    try {
        is = new ByteArrayInputStream(multipartFile.getBytes());
        byte[] buffer = new byte[1024];
        MessageDigest digest = MessageDigest.getInstance("MD5");
        int numRead = 0;
        while (numRead != -1) {
            numRead = is.read(buffer);
            if (numRead > 0) {
                digest.update(buffer, 0, numRead);
            }
        }
        byte[] md5Bytes = digest.digest();
        return convertHashToString(md5Bytes);
    } catch (Exception e) {
        return null;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
            }
        }
    }
}

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

public static File createFile(MultipartFile multipartFile) throws IOException {
    String fileName = generateFileName(multipartFile);
    String contentType = generateContentType(multipartFile);
    byte[] source = multipartFile.getBytes();
    File file = new File(source, contentType, fileName);
    return file;//from w  w  w . ja v a  2  s . c om
}

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

private static boolean save(String fileName, String path, MultipartFile image) {
    try {/*from  ww w. ja va  2s. co  m*/
        File file = new File(path + "//" + fileName);
        FileUtils.writeByteArrayToFile(file, image.getBytes());
    } catch (IOException ex) {
        return false;
    }
    return true;
}

From source file:hr.softwarecity.osijek.utility.Multimedia.java

/**
 * Method for uploading files/* w  w w . j a v  a  2 s  .c  o m*/
 * @param path path to put file
 * @param file file to upload
 * @return path to file or Failed keyword on fail
 * @throws java.nio.file.FileSystemException
 * @throws java.io.FileNotFoundException
 */
public static String handleFileUpload(String path, MultipartFile file) throws IOException {
    Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "Initiating file upload");
    if (!file.isEmpty()) {
        byte[] bytes = file.getBytes();
        BufferedOutputStream stream = new BufferedOutputStream(
                new FileOutputStream(new File(path, file.getOriginalFilename())));
        stream.write(bytes);
        stream.close();
        Logger.getLogger("Multimedia.java").log(Logger.Level.INFO, "File uploaded");
        return path;
    } else {
        Logger.getLogger("Multimedia.java").log(Logger.Level.ERROR, "File size 0! ");
        return null;
    }
}

From source file:de.unimannheim.spa.process.util.FileUtils.java

public static File convertMultipartToFile(MultipartFile multipartFile)
        throws IllegalStateException, IOException {
    File convertedFile = new File(multipartFile.getOriginalFilename());
    FileOutputStream fos = new FileOutputStream(convertedFile);
    fos.write(multipartFile.getBytes());
    fos.close();/*from   w  ww  . j ava  2s  .  com*/
    return convertedFile;
}

From source file:de.ingrid.iplug.excel.service.SheetsService.java

/**
 * Create sheets./*ww  w  .ja  v a 2s .c o m*/
 * 
 * @param multipartFile
 * @return Created sheets.
 * @throws IOException
 */
public static Sheets createSheets(final MultipartFile multipartFile) throws IOException {
    final byte[] bytes = multipartFile.getBytes();
    final Sheets sheets = createSheets(new ByteArrayInputStream(bytes));
    for (final Sheet sheet : sheets) {
        sheet.setFileName(multipartFile.getOriginalFilename());
        sheet.setWorkbook(bytes);
    }
    return sheets;
}