admin 管理员组文章数量: 1086019
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?
本文标签:
版权声明:本文标题:c# - Google Export method not getting the file downloaded in the requested mimetype format for Google Workspace documents - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1743996943a2515749.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论