2012-04-27 41 views
0

對於公共鏈接,它工作正常,但在我的情況下,我需要從本地磁盤上傳圖像文件。我將圖像轉換爲base64格式,並將html文件寫入本地磁盤,以便可以在瀏覽器中打開html文件並顯示圖像,但文檔在google doc中只是一個空文件,即使我將該文件拖到Google docs圖像仍然不存在。我的代碼如下:無法上傳本地圖像文件到格式轉換後的谷歌文檔

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

看我的經驗水平是隻有幾年,所以我可能是錯的,但....我的理解是,你可以不再使用

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


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

希望有人更多的知識將確認或拒絕

+0

Resumalbe文件上傳器會將圖像上傳到Google Doc中,原始格式,這將花費存儲空間使用,也無法通過DocumentList API取回。 Google已經提出這個問題,請參閱第3101期http://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3101 – user1335794 2012-05-22 09:11:38