Skip to content

Instantly share code, notes, and snippets.

@kdmukai
Created July 23, 2011 19:58
Show Gist options
  • Save kdmukai/1101813 to your computer and use it in GitHub Desktop.
Save kdmukai/1101813 to your computer and use it in GitHub Desktop.
Google's example code to upload a file to Google Docs
DocumentListEntry uploadedEntry = uploadFile("/path/to/your/file.doc", "TitleToUse");
System.out.println("Document now online @ :" + uploadedEntry.getHtmlLink().getHref());
public DocumentListEntry uploadFile(String filepath, String title)
throws IOException, ServiceException {
File file = new File(filepath);
DocumentListEntry newDocument = new DocumentListEntry();
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
newDocument.setFile(new File(filepath), mimeType);
newDocument.setTitle(new PlainTextConstruct(title));
return client.insert(new URL("https://docs.google.com/feeds/documents/private/full/"), newDocument);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment