简体   繁体   English

Google Drive API v2:InsertMediaUpload - 收到空响应

[英]Google Drive API v2: InsertMediaUpload - Null response received

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

The authentication takes place properly (using impersonation) - via service account (AssertionFlowClient).身份验证正确进行(使用模拟) - 通过服务帐户(AssertionFlowClient)。 Access token is obtained.获取访问令牌。 Service account has been granted domain wide privileges服务帐户已被授予域范围的权限

I am able to get the parent folder - ID (strRootFolder) via Service.Files.List();我能够通过 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();

However Upload method does not send any request.但是上传方法不发送任何请求。 No exception is thrown.不会抛出任何异常。 Fiddler trace shows no request has been sent and hence request.responsebody is always null. Fiddler 跟踪显示未发送任何请求,因此 request.responsebody 始终为空。

Am I missing something ?我错过了什么吗?

If some exception occur during the upload, the return object (IUploadProgress) should contain the exception (take a look at the Exception property).如果在上传过程中发生某些异常,返回对象 (IUploadProgress) 应包含异常(查看 Exception 属性)。 Please check what is the exception.请检查是什么异常。

You should also consider using UploadAsync which doesn't block your code (but first you should understand what is the exception)您还应该考虑使用不会阻止您的代码的 UploadAsync(但首先您应该了解什么是异常)

You should look into Exception from your upload, that will give you a better idea of the actual problem.您应该从上传中查看 Exception,这将使您更好地了解实际问题。

Sample code:示例代码:

var progress = request.Upload();

if (progress.Exception != null)
{
   //Log execption, or break here to debug
   YourLoggingProvider.Log(progress.Exception.Message.ToString());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM