I have problem with upload a microsoft/libre office document for edit via google apps. For spreadsheet it's working properly but for docs isn't.
When I upload a file with extension like *.odt, *.docx I can see the content by google viewer on Google Drive but when I click edit using button on top of document the Google Drive creates a new file with the same content and name but I don't have information about original file ID in description or any capitability. Any ideas how to upload a document ready for edit online?
private async Task<string> UploadFileToGoogleDrive(string filePath, GoogleDriveFile file)
{
var fileData = new Google.Apis.Drive.v3.Data.File()
{
Name = file.Name,
MimeType = file.MimeType
};
if (!String.IsNullOrEmpty(file.ParentId))
fileData.Parents = new List<string>() { file.ParentId };
FilesResource.CreateMediaUpload request;
using (var stream = new FileStream(filePath, FileMode.Open))
{
request = _driveService.Files.Create(fileData, stream, StringEnum.GetStringValue(file.FileContent));
request.Fields = "id";
var uploadProgress = await request.UploadAsync();
if (uploadProgress.Exception != null)
throw uploadProgress.Exception;
}
return request.ResponseBody.Id;
}
File mime types https://developers.google.com/drive/v3/web/manage-downloads
Or with "importFormats" parameter. https://developers.google.com/drive/v3/reference/about/get