Fail to upload a image file into Google Doc via java api

故事扮演 提交于 2019-12-13 00:11:53

问题


below is my code

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);

the document was created successful, but it did not contain anything.


回答1:


try the following

client.insert(new URL("https://docs.google.com/feeds/documents/private/full/?convert=false"), newDocument);

i think the ?convert=false bit is important, not sure how you do that without the url

client.insert(new URL(destFolderUrl+ "?convert=false"), newDocument);

would hopefully work in your case



来源:https://stackoverflow.com/questions/10170579/fail-to-upload-a-image-file-into-google-doc-via-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!