Google drive api v3 response null

随声附和 提交于 2019-12-24 01:39:32

问题


I want to try upload file google drive and my code is here:

 public static File UploadFile(DriveService service, string fileName, string filePath, string description, string parent)
{
  var fileMetadata = new File
  {
    Name = fileName,
    MimeType = GetMimeType(fileName),
    Description = description,
    OriginalFilename = fileName,
  };

  FilesResource.CreateMediaUpload request;
  using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
  {
      request = service.Files.Create(fileMetadata, stream, GetMimeType(fileName));
      request.Fields = "id";
      request.Alt=FilesResource.CreateMediaUpload.AltEnum.Json;
      request.Upload();
  }
  var file = request.ResponseBody;
  Console.WriteLine("File ID: " + file.Id);


  return null;

}

But Response body is always null and i cant upload. By the way i saw error in this picture:

google-api-dotnet-client 1.16.0.0 gzip the format of the invalid value

Anyone idea how to solve this problem and upload files google drive.


回答1:


It appears V3 has replaced InsertMediaUpload for CreateMediaUpload and when using a service account at least the ResponseBody will always be returned as NULL.

This makes it difficult to determine the ID of the file and later find it to modify permissions or do anything else.



来源:https://stackoverflow.com/questions/39468798/google-drive-api-v3-response-null

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