无法通过java api将图像文件上传到Google Doc

时间:2012-04-16 08:06:40

标签: java google-docs google-docs-api

下面是我的代码

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

文档创建成功,但它没有包含任何内容。

1 个答案:

答案 0 :(得分:3)

尝试以下

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

我认为?convert=false位很重要,不知道如果没有网址

,你会怎么做
client.insert(new URL(destFolderUrl+ "?convert=false"), newDocument);

希望能够适用于您的情况