最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Google Export method not getting the file downloaded in the requested mimetype format for Google Workspace documents - Stac

programmeradmin0浏览0评论

I'm using the Google Drive API (Google.Apis.Drive.v3) to export Google Workspace files (Docs, Sheets, etc.) into specific MIME types using the Files.Export method. However, the downloaded file does not match the requested MIME type—it downloads as a plain file instead of the expected format.

using (Stream stream = await service.GetBlobWriteStream(asset.BlobUri))
{
  var _driveService = new DriveService(new BaseClientService.Initializer
   {
    HttpClientInitializer = GetUserCredential(UserId).Result,
    ApplicationName = _googleAuthConfig.CurrentValue.AppName
   });

   var exportRequest = _driveService.Files.Export(asset.FileId, requestedMimeType);
   long previousSize = 0;
   long currentSize = 0;
   exportRequest.MediaDownloader.ProgressChanged += async progress =>
   {     
    await UpdateDownloadProgress(progress);
   }
   result = await exportRequest.DownloadAsync(stream, cancellationToken); 
   await stream.FlushAsync(cancellationToken);
   stream.Close();
   return result;
}

Problem Statement I'm trying to export a Google Doc (application/vnd.google-apps.document) to Word format (application/vnd.openxmlformats-officedocument.wordprocessingml.document) using the Drive API Export method.

According to the Google Drive Export Formats Documentation, this is a valid conversion.

However, the downloaded file is not in the expected .docx format but appears as a plain file.

Expected vs. Actual Behavior

✅ Expected: The file should be converted to .docx format.

❌ Actual: The file is not in .docx format but some unrecognized format.

What I've Tried: Verified that the requestedMimeType is correctly set to "application/vnd.openxmlformats-officedocument.wordprocessingml.document".

Confirmed that Files.Export() is the correct method for exporting Google Workspace files.

Checked Google's documentation, and this MIME type mapping should be supported.

Ensured the file is a Google Docs file and not a regular uploaded file (since Export() works only on native Google Workspace files).

Questions:

Why is the exported file not in the requested MIME type?

Are there any additional headers or parameters required for correct format conversion?

Is there any known issue with the Files.Export() method for certain file types?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论