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;
}
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);
}
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);
}
Aggregations