Search in sources :

Example 1 with Thumbnail

use of com.google.api.services.drive.model.File.ContentHints.Thumbnail in project OpenRefine by OpenRefine.

the class UploadCommand method uploadOpenRefineProject.

private String uploadOpenRefineProject(Project project, String token, String name, List<Exception> exceptions) {
    FileOutputStream fos = null;
    try {
        java.io.File filePath = java.io.File.createTempFile(name, ".tgz");
        filePath.deleteOnExit();
        fos = new FileOutputStream(filePath);
        FileProjectManager.gzipTarToOutputStream(project, fos);
        Thumbnail tn = new Thumbnail();
        tn.setMimeType("image/x-icon").encodeImage(getIconImage());
        ContentHints contentHints = new ContentHints();
        contentHints.setThumbnail(tn);
        File fileMetadata = new File();
        fileMetadata.setName(name + ".tar.gz").setDescription(METADATA_DESCRIPTION).setContentHints(contentHints);
        FileContent projectContent = new FileContent("application/x-gzip", filePath);
        File file = GoogleAPIExtension.getDriveService(token).files().create(fileMetadata, projectContent).setFields("id").execute();
        logger.info("File ID: " + file.getId());
        return file.getId();
    } catch (IOException e) {
        logger.error(ExceptionUtils.getStackTrace(e));
        exceptions.add(e);
    }
    return null;
}
Also used : FileContent(com.google.api.client.http.FileContent) ContentHints(com.google.api.services.drive.model.File.ContentHints) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Thumbnail(com.google.api.services.drive.model.File.ContentHints.Thumbnail) File(com.google.api.services.drive.model.File)

Aggregations

FileContent (com.google.api.client.http.FileContent)1 File (com.google.api.services.drive.model.File)1 ContentHints (com.google.api.services.drive.model.File.ContentHints)1 Thumbnail (com.google.api.services.drive.model.File.ContentHints.Thumbnail)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1