user1335794
user1335794

Reputation: 1092

Faild to upload a image file into Google Doc with google format via java api

I need upload a image into Google doc with google format in order to retrieving it back and saving the storage uasage as well. Below it my code sample, it was work fine but broken recently, What I got just a empty document. Could anyone help me?

DocsService client = new DocsService("testappv1"); 
client.setUserCredentials(username, password); 
client.setProtocolVersion(DocsService.Versions.V2); 
File file = new File("C:/test.jpg"); 
DocumentEntry newDocument = new DocumentEntry(); 
newDocument.setTitle(new PlainTextConstruct("test")); 
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
newDocument.setMediaSource(new MediaFileSource(file, mimeType)); 
newDocument = client.insert(destFolderUrl, newDocument); 

Upvotes: 0

Views: 213

Answers (1)

Alain
Alain

Reputation: 6034

Please have a look at this answer. Also, remove this line from your code:

client.setProtocolVersion(DocsService.Versions.V2);

You should use the default version (3.0) whenever possible.

Upvotes: 1

Related Questions