无法通过Java API将图像文件上传到Google文档 [英] Fail to upload a image file into Google Doc via java api

查看:62
本文介绍了无法通过Java API将图像文件上传到Google文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码

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.

推荐答案

尝试以下

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

我认为?convert=false位很重要,不确定在没有url的情况下怎么做

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

这篇关于无法通过Java API将图像文件上传到Google文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆