* @return ID of the added file
* @throws Exception
*/
public File addFileInGoogleDrive(Node fileNode) throws Exception {
Drive driveService = getDriveService();
String mimeType = fileNode.getNode("jcr:content").getProperty("jcr:mimeType").getString();
InputStream documentIS = fileNode.getNode("jcr:content").getProperty("jcr:data").getStream();
// Insert a file
File body = new File();
body.setTitle(fileNode.getName());
body.setMimeType(mimeType);
// TODO files are created on file system, handle it right...
java.io.File fileContent = new java.io.File(fileNode.getName());
OutputStream out = new FileOutputStream(fileContent);
byte buf[] = new byte[1024];
int len;
while ((len = documentIS.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
documentIS.close();
FileContent mediaContent = new FileContent(mimeType, fileContent);
Insert insert = driveService.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setDirectUploadEnabled(true);
File file = insert.setConvert(true).execute();
return file;
}