Google Drive API v2:InsertMediaUpload - 收到空回复 [英] Google Drive API v2: InsertMediaUpload - Null response received

查看:198
本文介绍了Google Drive API v2:InsertMediaUpload - 收到空回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:Drive v2: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 =标题;
flUpload.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方法不会发送任何请求。没有例外被抛出。



我错过了什么吗?

请检查是什么例外。



您还应该考虑使用不会阻止您的代码的UploadAsync(但首先您应该了解什么是异常情况)

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

The authentication takes place properly (using impersonation) - via service account (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();

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.

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). 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)

这篇关于Google Drive API v2:InsertMediaUpload - 收到空回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆