在Azure,Google Drive Api文件上传失败,返回null

时间:2016-04-29 17:08:27

标签: c# azure google-drive-api

我正在尝试使用Google Drive Api将图片上传到Google云端硬盘。我们的网站托管在Azure服务器上。上传适用于本地PC和另一台非云的物理服务器。

调用

后,

insertRequest.ResponseBody 为空

insertRequest.Upload()

但我无法收到任何错误消息。这是我正在使用的代码;

          ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] { DriveService.Scope.DriveFile }
           }.FromCertificate(certificate));

        // Create the service using the client credentials.
        service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = applicationName
        });

        var uploadStream = new System.IO.MemoryStream(Convert.FromBase64String(base64));
        // Get the media upload request object.
        Google.Apis.Drive.v2.FilesResource.InsertMediaUpload insertRequest = service.Files.Insert(
            new File
            {
                Title = fileTitle,
                Parents = new List<ParentReference>() { new ParentReference() { Id = folderId } }
            },
            uploadStream,
            "image/jpeg");
        insertRequest.ProgressChanged += Upload_ProgressChanged;
        insertRequest.ResponseReceived += Upload_ResponseReceived;
        insertRequest.Upload();
        File file = insertRequest.ResponseBody;

1 个答案:

答案 0 :(得分:0)

我们解决了这个问题。这完全是我们的错误。

没有具有给定ID的文件夹。提供现有文件夹的ID解决了这个问题。

如果没有具有给定ID的文件夹,则会抛出异常“对象引用未设置为对象的实例”。我们首先认为它是我们的C#代码的例外。但显然,谷歌SDK会抛出它。

相关问题