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?