无法通过java api将嵌入到HTML中的本地图像文件作为数据URI上载到Google文档中 [英] Could not upload a local image file embedded into HTML as a data URI into google doc via java api

查看:137
本文介绍了无法通过java api将嵌入到HTML中的本地图像文件作为数据URI上载到Google文档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从本地磁盘上传图片文件。我将图像转换为base64格式,并将html文件写入本地磁盘,以便可以在浏览器中打开html文件并显示图像,但文档在google doc中只是一个空文件,即使我将该文件拖到Google docs图像仍然不存在。我的代码如下:

I need upload a image file from local disk. I converted the image into base64 format, and write the html file into local disk as well, that html file can be opened in browser with image showing, but the document in google doc just an empty file, even I drag that html file into google docs the image still not there. My code is below:

DocsService client = new DocsService("testappv3");
client.setUserCredentials("username", "password");
File file = new File("c:/test.bmp");
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

int read;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
    out.write(buff, 0, read);
}
out.flush();

String base64 = Base64.encode(out.toByteArray());
String mimeType = DocumentListEntry.MediaType.fromFileName(file.getName()).getMimeType();
String html = "<html><body><img src=\"data:" + mimeType + ";base64," + base64 + "\"/></body></html>";


URL destFolderUrl = new URL("https://docs.google.com/feeds/default/private/full/<FOLDER_ID>/contents");
DocumentEntry newDocument = new DocumentEntry();
newDocument.setTitle(new PlainTextConstruct("test"));
newDocument.setMediaSource(new MediaByteArraySource(html.getBytes(), "text/html"));
newDocument = client.insert(destFolderUrl, newDocument);


推荐答案

这看起来像一个错误,我们试图修复当我们遇到问题时,我会尽快回复您。

This looks like a bug, we are trying to fix it, and I will get back to you when we have a fix.

感谢您的耐心配合。

这篇关于无法通过java api将嵌入到HTML中的本地图像文件作为数据URI上载到Google文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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