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);
}
use of com.google.api.client.http.FileContent 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;
}
Aggregations