com.google.api.client.http.FileContent

Here are the examples of the java api class com.google.api.client.http.FileContent taken from open source projects.

1. AbstractGoogleDriveTestSupport#uploadTestFile()

Project: camel
File: AbstractGoogleDriveTestSupport.java
protected File uploadTestFile() {
    File fileMetadata = new File();
    fileMetadata.setTitle(UPLOAD_FILE.getName());
    FileContent mediaContent = new FileContent(null, UPLOAD_FILE);
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", fileMetadata);
    // parameter type is com.google.api.client.http.AbstractInputStreamContent
    headers.put("CamelGoogleDrive.mediaContent", mediaContent);
    File result = requestBodyAndHeaders("google-drive://drive-files/insert", null, headers);
    return result;
}

2. GsUploadManager#upload()

Project: secor
File: GsUploadManager.java
@Override
public Handle<?> upload(LogFilePath localPath) throws Exception {
    final String gsBucket = mConfig.getGsBucket();
    final String gsKey = localPath.withPrefix(mConfig.getGsPath()).getLogFilePath();
    final File localFile = new File(localPath.getLogFilePath());
    final boolean directUpload = mConfig.getGsDirectUpload();
    LOG.info("uploading file {} to gs://{}/{}", localFile, gsBucket, gsKey);
    final StorageObject storageObject = new StorageObject().setName(gsKey);
    final FileContent storageContent = new FileContent(Files.probeContentType(localFile.toPath()), localFile);
    final Future<?> f = executor.submit(new Runnable() {

        @Override
        public void run() {
            try {
                Storage.Objects.Insert request = mClient.objects().insert(gsBucket, storageObject, storageContent);
                if (directUpload) {
                    request.getMediaHttpUploader().setDirectUploadEnabled(true);
                }
                request.getMediaHttpUploader().setProgressListener(new MediaHttpUploaderProgressListener() {

                    @Override
                    public void progressChanged(MediaHttpUploader uploader) throws IOException {
                        LOG.debug("[{} %] upload file {} to gs://{}/{}", (int) uploader.getProgress() * 100, localFile, gsBucket, gsKey);
                    }
                });
                request.execute();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    return new FutureHandle(f);
}

3. DriveFilesIntegrationTest#testUpdate1()

Project: camel
File: DriveFilesIntegrationTest.java
@Test
public void testUpdate1() throws Exception {
    // First retrieve the file from the API.
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    // using String message body for single parameter "fileId"
    final File file = requestBody("direct://GET", fileId);
    // File's new metadata.
    file.setTitle("camel.png");
    // File's new content.
    java.io.File fileContent = new java.io.File(TEST_UPLOAD_IMG);
    FileContent mediaContent = new FileContent(null, fileContent);
    // Send the request to the API.
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", file);
    // parameter type is com.google.api.client.http.AbstractInputStreamContent
    headers.put("CamelGoogleDrive.mediaContent", mediaContent);
    File result = requestBodyAndHeaders("direct://UPDATE_1", null, headers);
    assertNotNull("update result", result);
    LOG.debug("update: " + result);
}