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:com.glaf.core.util.UploadUtils.java

/**
 * ??//from w  w  w . j a  v  a 2 s .c o m
 * 
 * @param request
 * @param fileParam
 * @return
 */
public static byte[] getBytes(HttpServletRequest request, String fileParam) {
    MultipartFile mFile = getMultipartFile(request, fileParam);
    byte[] bytes = null;
    try {
        if (mFile != null && !mFile.isEmpty()) {
            bytes = mFile.getBytes();
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        ex.printStackTrace();
    }
    return bytes;
}

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");
    }/*from  w ww  .j av  a2  s . c om*/

    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.wavemaker.tools.spring.ComplexReturnBean.java

public static String testUpload(@ParamName(name = "param1") String param1,
        @ParamName(name = "param2") MultipartFile param2) throws IOException {
    return param1 + new String(param2.getBytes());
}

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

private InputStream inputStream(MultipartFile file) throws IOException {
    return new ByteArrayInputStream(file.getBytes());
}

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

@Override
public String upload1(String folder, MultipartFile file, String message) {
    try {/*from  www . j av  a  2 s  . c o  m*/
        return new String(file.getBytes()) + ":" + message;
    } catch (IOException e) {
        throw new RuntimeException("Can't get file content", e);
    }
}

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

@Override
public String upload2(MultipartFile file, String folder, String message) {
    try {/*from   w ww . j av a  2 s  .c  om*/
        return new String(file.getBytes()) + ":" + message;
    } catch (IOException e) {
        throw new RuntimeException("Can't get file content", e);
    }
}

From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowRevisionControllerTest.java

@Test
public void testCreate() throws Exception {
    MultipartFile mockedFile = mock(MultipartFile.class);
    when(mockedFile.getBytes()).thenReturn(null);
    workflowRevisionController.create(BUCKET_ID, WF_ID, Optional.empty(), mockedFile);
    verify(workflowRevisionService, times(1)).createWorkflowRevision(BUCKET_ID, Optional.of(WF_ID), null,
            Optional.empty());/*from  ww  w.ja v  a 2 s. c om*/
}

From source file:com.weavers.duqhan.util.FileUploader.java

public static CloudineryImageDto uploadImage(MultipartFile file) {
    CloudineryImageDto imageBean = new CloudineryImageDto();
    imageBean.setUrl("failure");
    String timeInMili = String.valueOf(new Date().getTime());
    Map params = Cloudinary.asMap("public_id", timeInMili);
    Calendar calendar = Calendar.getInstance();
    List<Transformation> eager = Arrays.asList(new Transformation().width(512).height(512).crop("thumb"));
    Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap("cloud_name", CLOUD_NAME, "api_key", API_KEY,
            "tags", "product", "timestamp", calendar.getTimeInMillis(), "api_secret", API_SECRET,
            // "upload_preset", "gpucdhrn",
            //  "transformation", incoming,
            "eager", eager));

    Map uploadResult;//from www  . j  ava  2 s  .  c  o m
    String url = null;
    try {
        //            cloudinary.url().type("fetch").imageTag("http://upload.wikimedia.org/wikipedia/commons/0/0c/Scarlett_Johansson_Csars_2014.jpg");
        byte[] file1 = file.getBytes();
        uploadResult = cloudinary.uploader().upload(file1, params);
        //            cloudinary.url().transformation(new Transformation().width(512).height(512).crop("fill")).imageTag(params);
        String publicId = (String) uploadResult.get("public_id");
        url = (String) uploadResult.get("url");
        String signature = (String) uploadResult.get("signature");
        String format = (String) uploadResult.get("format");
        String secureUrl = (String) uploadResult.get("secure_url");
        Integer version = (Integer) uploadResult.get("version");

        //<editor-fold defaultstate="collapsed" desc="Image Bean">
        imageBean.setFormat(format);
        imageBean.setPublicId(publicId);
        imageBean.setSecureUrl(secureUrl);
        imageBean.setSignature(signature);
        imageBean.setVersion(Long.valueOf(version));
        imageBean.setUrl(url);
        //</editor-fold>

    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex);
        //            System.out.println("eeeeeeeeeee"+ex.getLocalizedMessage());
        imageBean.setUrl("failure");
    }
    return imageBean;
}

From source file:files.FileStorage.java

public void saveFile(Long id, MultipartFile file) throws IOException {
    File newFile = new File(filePath + id);
    FileUtils.writeByteArrayToFile(newFile, file.getBytes());
}

From source file:com.web.mavenproject6.controller.DocumentUploadController.java

@ResponseBody
@RequestMapping(value = "/uploadMultipleFile", method = RequestMethod.POST)
public Object uploadMultipleFileHandler(@RequestParam("file") MultipartFile[] files) {
    System.out.print("PATH IS A:" + env.getProperty("upload.files.dir"));
    String buf = "";
    List<String> l = new ArrayList<>();
    for (MultipartFile file : files) {
        try {/*w  w  w . j  a  va  2 s .  co m*/
            byte[] bytes = file.getBytes();

            String rootPath = env.getProperty("upload.files.dir");

            File dir = new File(rootPath);
            if (!dir.exists()) {
                dir.mkdirs();
                dir.setWritable(true);
            }
            File serverFile = new File(rootPath + File.separator + file.getOriginalFilename());
            serverFile.createNewFile();
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();
            System.err.println(file.getOriginalFilename());
            buf = XLSParser.parse(env.getProperty("upload.files.dir") + "\\" + file.getOriginalFilename());

            l.add(file.getOriginalFilename());
        } catch (Exception e) {

        }
    }
    // ModelAndView model = new ModelAndView("jsp/uploadedFiles");
    //model.addObject("list", l.toArray());
    // model.addObject("buffer",buf);
    //  return model;
    return buf;
}