Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 565
Prasanna Avatar asked May 07 '26 09:05

Prasanna


1 Answers

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)

like image 86
peleyal Avatar answered May 09 '26 02:05

peleyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!