Google Drive API v2: InsertMediaUpload - Null response received

扶醉桌前 提交于 2019-12-12 15:16:04

问题


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 ?


回答1:


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)



来源:https://stackoverflow.com/questions/19021931/google-drive-api-v2-insertmediaupload-null-response-received

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!