Google Drive API v2: InsertMediaUpload - Null response received

问题描述 投票:3回答:2

使用: Drive v2. 1.5.0.99 Beta, .NET Framework: : 1.5.0.99 Beta, .NET Framework: 4.5

通过服务账户(AssertionFlowClient),正确地进行了认证(使用冒名顶替),获得了访问令牌。 服务账户已被授予域范围的权限

我能够通过Service.Files.List()获得父文件夹--ID(strRootFolder)。

byte[] byteArray = System.IO.File.ReadAllBytes(FileName);

Google.Apis.Drive.v2.Data.File flUpload = new Google.Apis.Drive.v2.Data.File();
flUpload.Title = Title;
flUpload.Description = Description;
flUpload.MimeType = MimeType;
flUpload.Parents = new List<ParentReference>() { new ParentReference() { Id = strRootFolder } };

Google.Apis.Drive.v2.FilesResource.InsertMediaUpload drvRequest = drvService.Files.Insert(flUpload, new System.IO.MemoryStream(byteArray), "text/plain");
drvRequest.Upload();

然而Upload方法没有发送任何请求。没有抛出任何异常。Fiddler跟踪显示没有请求被发送,因此request.responsebody总是null。

我是不是错过了什么?

c# .net google-drive-api google-api-dotnet-client
2个回答
1
投票

如果在上传过程中发生了一些异常,返回对象(IUploadProgress)应该包含异常(看看Exception属性)。请检查是什么异常。

你也应该考虑使用UploadAsync,它不会阻挡你的代码(但首先你应该了解什么是异常)。


0
投票

你应该看看你上传的Exception,那会让你更好地了解实际问题。

示例代码。

var progress = request.Upload();

if (progress.Exception != null)
{
   //Log execption, or break here to debug
   YourLoggingProvider.Log(progress.Exception.Message.ToString());
}
© www.soinside.com 2019 - 2024. All rights reserved.