2016-04-29 94 views
1

我試圖使用Google Drive Api將圖像上傳到Google雲端硬盤。我們的網站託管在Azure服務器上。在本地PC和另一臺不是雲的物理服務器上都可以上傳。在Azure中,Google Drive Api文件上傳失敗,返回null

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; 
+0

您正嘗試從Azure託管的網站上傳文件,我是對的嗎? –

+0

是的,你是對的。對不起,遲到的答案。 –

回答

0

我們解決了這個問題。這完全是我們的錯誤。

沒有給定ID的文件夾。給現有文件夾的ID解決了問題。

當沒有給定ID的文件夾時,它會拋出一個異常「未將對象引用設置爲對象的實例」。我們首先認爲這是我們的C#代碼中的一個例外。但顯然,Google SDK會拋出它。