I have a document (Google’s own document) in Google Drive that I need to update from my Java application. What I have done so far is to download the document as html
String downloadUrl = doc.getExportLinks().get("text/html");
HttpResponse resp = service.getRequestFactory()
.buildGetRequest(new GenericUrl(downloadUrl))
.execute();
String contents = IOUtils.toString(resp.getContent());
Then I update the contents in the object Stringand send the update to Drive:
ByteArrayContent mediaContent = ByteArrayContent.fromString("text/html", contents);
service.files().update(doc.getId(), doc, mediaContent).execute();
This is great for very simple documents. But if the document contains an image, it disappears. The srctag attribute is imgempty.
Does Google provide some other ways to update the contents of a Google Doc? Is there an API similar to the Google Spreadsheet API ?