Created
July 23, 2011 19:58
-
-
Save kdmukai/1101813 to your computer and use it in GitHub Desktop.
Google's example code to upload a file to Google Docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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