2012-04-30 59 views
3

我需要從本地磁盤上傳圖像文件。我將圖像轉換爲base64格式,並將html文件寫入本地磁盤,以便可以在瀏覽器中打開html文件並顯示圖像,但文檔在google doc中只是一個空文件,即使我將該文件拖到Google docs圖像仍然不存在。我的代碼如下:無法上傳本地圖像文件嵌入到HTML作爲數據URI到谷歌文檔通過java api

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

爲什麼你上傳一個帶有text/html的圖像作爲內容類型? –

+0

beacse我將這個圖像文件嵌入到一個html文件中,然後將html文件上傳到google文檔中。行圖片文件無法上傳到谷歌文檔 – user1335794

回答

0

這看起來像一個錯誤,我們正在努力解決這個問題,我會盡快給你的時候,我們有一個修復。

感謝您的耐心等待。

+0

非常感謝,我會等待你的好消息:) – user1335794

+0

是否有關於該問題/錯誤的任何消息? 謝謝。 –

+0

@ user1335794任何進度或建議的解決方法? –

相關問題