Google Drive API集成不适用于实时URL

时间:2019-01-16 11:43:27

标签: c# integration flysystem-google-drive

我正在尝试使用Google Drive API集成上传文档,在localhost情况下可以正常工作,但不能在实时域上工作。

using (var stream = new FileStream(@"" + folderPathForCredentials, FileMode.Open, FileAccess.ReadWrite))
{
    // The file token.json stores the user's access and refresh tokens, and is created
    // automatically when the authorization flow completes for the first time.

    String FolderPath = @"" + folderPathForToken;
    String FilePath = Path.Combine(FolderPath, "token.json");

    stream.Dispose();
    stream.Close();

    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        new ClientSecrets
        {
            ClientId = clientID,
            ClientSecret = clientSecret
        },
        Scopes,
        "user",
        CancellationToken.None,
        new FileDataStore(FilePath, true)).Result;
}

//create Drive API service.
DriveService service = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = applicationName,
});
return service;

这是要在Google云端硬盘上上传的代码。

FilesResource.CreateMediaUpload request;
if (System.IO.File.Exists(path))
{
    using (var stream = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
    {
        request = _service.Files.Create(FileMetaData, stream, FileMetaData.MimeType);
        request.Fields = "id";
        request.Upload();
        stream.Dispose();
        stream.Close();
        System.IO.File.Delete(path);
        //return request.ResponseBody;
        return Json(new JsonData { IsSuccess = true, Message = "Uploaded Successfully", Data = null });
    }
}

让我帮助您配置具有实时域的驱动器。

0 个答案:

没有答案