Android 将文档上载到google drive时松开换行符
当我把我的文档上传到谷歌硬盘时,我松开了换行符。将文档作为文本文件上载时,它可以工作:Android 将文档上载到google drive时松开换行符,android,google-drive-api,Android,Google Drive Api,当我把我的文档上传到谷歌硬盘时,我松开了换行符。将文档作为文本文件上载时,它可以工作: ByteArrayContent content = ByteArrayContent.fromString("text/plain", body); File uploadedFile = drive.files().update( file.getId(), file, content).setSetModifiedDate(true).execute();
ByteArrayContent content = ByteArrayContent.fromString("text/plain", body);
File uploadedFile = drive.files().update(
file.getId(), file, content).setSetModifiedDate(true).execute();
但是,当我添加setConvert(true)将文件作为Google文档上传时,我松开了换行符
ByteArrayContent content = ByteArrayContent.fromString("text/plain", body);
File uploadedFile = drive.files().update(
file.getId(), file, content).setConvert(true).setSetModifiedDate(true).execute();
ByteArrayContent content = ByteArrayContent.fromString("text/plain", body);
File updatedFile = drive.files().update(
driveFile.getId(), driveFile, content).setConvert(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 uploadedFile = drive.files().update(
file.getId(), file, content).setConvert(true).setSetModifiedDate(true).execute();
ByteArrayContent content = ByteArrayContent.fromString("text/plain", body);
File updatedFile = drive.files().update(
driveFile.getId(), driveFile, content).setConvert(true).execute();
发现了问题。在更新文档之前,我下载了其元数据:
File driveFile = drive.files().get(resourceID).execute();
此文件的mime类型为Google文档。在更新之前,我必须将mimetype重置为“text/plain”