0

对于公共链接,它工作正常,但在我的情况下,我需要从本地磁盘上传图像文件。我将图片转换为base64格式,并将html文件也写入本地磁盘,该html文件可以在浏览器中打开并显示图像,但google doc中的文档只是一个空文件,即使我将该html文件拖到google文档图像仍然不存在。我的代码如下:

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

1 回答 1

0

看我的经验水平只有几年所以我很可能是错的但是....我的理解是你不能再使用

client.insert(destFolderUrl, newDocument);// but now must use ResumableGDataFileUploader


new ResumableGDataFileUploader.Builder(client, new URL(uploadLink), mediaFile, null )

希望有更多知识的人会确认或否认

于 2012-05-22T09:06:05.423 回答