Created
July 23, 2011 19:47
-
-
Save kdmukai/1101804 to your computer and use it in GitHub Desktop.
How to upload a File to Google Docs when you can't create a File in Google App Engine!
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
import com.google.gdata.client.docs.DocsService; | |
import com.google.gdata.data.MediaContent; | |
import com.google.gdata.data.PlainTextConstruct; | |
import com.google.gdata.data.docs.DocumentListEntry; | |
import com.google.gdata.data.docs.DocumentListEntry.MediaType; | |
import com.google.gdata.data.media.MediaByteArraySource; | |
import com.google.gdata.data.media.MediaSource; | |
import com.google.gdata.util.ContentType; | |
// ...skipping to the good part... | |
DocsService docsService = new DocsService("myname-webapp-1.0"); | |
// Authenticate our direct user access (using direct login credentials) | |
docsService.setUserCredentials(MY_USER_NAME, MY_PASSWORD); | |
DocumentListEntry newDocument = new DocumentListEntry(); | |
// Load the byte array into a MediaSource | |
MediaByteArraySource mediaSource = new MediaByteArraySource(byteData, MediaType.fromFileName(myFileName).getMimeType()); | |
MediaContent content = new MediaContent(); | |
content.setMediaSource(mediaSource); | |
content.setMimeType(new ContentType(mediaSource.getContentType())); | |
newDocument.setContent(content); | |
String gdocsFilename = new String("My Filename"); | |
newDocument.setTitle(new PlainTextConstruct(gdocsFilename)); | |
// Push it into Google Docs!! | |
DocumentListEntry uploadedRef = docsService.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newDocument); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment