Prasanna
Prasanna

Reputation: 31

Google Drive API v2: InsertMediaUpload - Null response received

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 ?

Upvotes: 3

Views: 1796

Answers (2)

roman m
roman m

Reputation: 26521

You should look into Exception from your upload, that will give you a better idea of the actual problem.

Sample code:

var progress = request.Upload();

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

Upvotes: 0

peleyal
peleyal

Reputation: 3512

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)

Upvotes: 1

Related Questions