Search in sources :

Example 6 with FileContent

use of com.google.api.client.http.FileContent in project camel by apache.

the class AbstractGoogleDriveTestSupport method uploadTestFile.

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;
}
Also used : FileContent(com.google.api.client.http.FileContent) HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File)

Example 7 with FileContent

use of com.google.api.client.http.FileContent in project camel by apache.

the class DriveFilesIntegrationTest method testUpdate1.

@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);
}
Also used : FileContent(com.google.api.client.http.FileContent) HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 8 with FileContent

use of com.google.api.client.http.FileContent in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method updateFile.

/**
	 * Method by update file
	 * 
	 * @param name
	 *            String name file
	 * @param fileContent
	 *            content file
	 * @param newMimeType
	 *            String with mime type
	 * @return boolean true if updated is success
	 */
public boolean updateFile(String name, java.io.File fileContent, String newMimeType) {
    File file = searchFile(name);
    FileContent mediaContent = new FileContent(newMimeType, fileContent);
    File updatedFile = null;
    try {
        updatedFile = drive.files().update(file.getId(), file, mediaContent).execute();
    } catch (Exception e) {
        log.error("Error actualizando fichero en google drive", e);
    }
    return (updatedFile != null);
}
Also used : FileContent(com.google.api.client.http.FileContent) File(com.google.api.services.drive.model.File) GeneralSecurityException(java.security.GeneralSecurityException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

FileContent (com.google.api.client.http.FileContent)8 File (com.google.api.services.drive.model.File)6 IOException (java.io.IOException)5 ParentReference (com.google.api.services.drive.model.ParentReference)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 Permission (com.google.api.services.drive.model.Permission)2 User (com.google.api.services.drive.model.User)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)1 AbstractInputStreamContent (com.google.api.client.http.AbstractInputStreamContent)1 InputStreamContent (com.google.api.client.http.InputStreamContent)1 AndroidPublisher (com.google.api.services.androidpublisher.AndroidPublisher)1 Edits (com.google.api.services.androidpublisher.AndroidPublisher.Edits)1 Upload (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Apks.Upload)1 Commit (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Commit)1 Insert (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Insert)1 Update (com.google.api.services.androidpublisher.AndroidPublisher.Edits.Tracks.Update)1 Apk (com.google.api.services.androidpublisher.model.Apk)1