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;
您正嘗試從Azure託管的網站上傳文件,我是對的嗎? –
是的,你是對的。對不起,遲到的答案。 –