2012-10-22 12 views
0

將我的文檔上傳到谷歌驅動器時,我鬆開了換行符。當上傳文檔另存爲文本文件,它的工作原理:將文檔上傳到谷歌驅動器時鬆動的線路中斷

ByteArrayContent content = ByteArrayContent.fromString("text/plain", body); 

    File uploadedFile = drive.files().update(
      file.getId(), file, content).setSetModifiedDate(true).execute(); 

但是,當我加入setConvert(真)上傳文件的谷歌文檔我失去換行符。

ByteArrayContent content = ByteArrayContent.fromString("text/plain", body); 
    File uploadedFile = drive.files().update(
      file.getId(), file, content).setConvert(true).setSetModifiedDate(true).execute(); 

我已嘗試添加不同類型的換行符我的字符串(如:「\ r」,「\ n」和甚至試圖同時使用)。有人知道我做錯了什麼嗎?

編輯

所以我發現我的一個新的文件的插入工作。當我對文件內容進行更新時,我將失去我的換行符。 這是我的插入,它的工作原理。

ByteArrayContent content = ByteArrayContent.fromString("text/plain", body); 
    drive.files().insert(file, content).setConvert(true).execute(); 

這是我的更新。現在我放棄了我的換行符。

ByteArrayContent content = ByteArrayContent.fromString("text/plain", body); 
    File updatedFile = drive.files().update(
      driveFile.getId(), driveFile, content).setConvert(true).execute(); 

回答

0

發現問題所在。在更新文檔之前,我下載了其元數據:

File driveFile = drive.files().get(resourceID).execute(); 

此文件具有MIME類型作爲Google文檔。在更新之前,我不得不將mimetype重置爲「text/plain」