Edit on Google Docs without converting

放肆的年华 提交于 2019-12-11 23:28:04

问题


I'm integrating my system with Google Drive. Everything is working so far, but one thing. I cannot edit the uploaded Word documents without converting them to Google Docs first.

I've read here it's possible using a Chrome plugin: https://support.google.com/docs/answer/6055139?hl=en

But that's not my goal. I'm storing the file's information on my database and then I just request the proper URL for editing and previewing. Previewing is working fine, but when I try the edit URL it says the file does not exist. If I convert the file (using Google Drive's interface) and pass the new ID it works. I don't want to convert the user's documents to Google Drive because they still use Word as their main editing software.

Is there a way to accomplish this?

This is how I'm doing right now:

public static File UploadFile(FileInfo fileInfo, Stream stream, string googleAccount)
{
    var mimetype = GetValidMimetype(fileInfo.MimeType);
    var parentFolder = GetParentFolder(fileInfo);
    var file = new File { Title = fileInfo.Title, MimeType = mimetype, Parents = parentFolder };
    var uploadRequest = _service.Files.Insert(file, stream, mimetype);

    uploadRequest.Upload();
    file = uploadRequest.ResponseBody;

    ShareFileWith(file.Id, googleAccount);

    return file;
}

This is the URL for editing (where {0} is the file ID):

https://docs.google.com/document/d/{0}/edit?usp=drivesdk

I know that in order to convert the file I just need to:

uploadRequest.Convert = true;

But again, that's not what I want. Is it possible?

Thanks!

EDIT

Just an update. Convert = true should've worked but it's not. I've raised an issue for that here https://github.com/google/google-api-dotnet-client/issues/712

Bottomline, it only works if I open the file on Google Docs and then use its Id...

来源:https://stackoverflow.com/questions/36224183/edit-on-google-docs-without-converting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!