0

我正在尝试使用 google Drive API 集成上传文档,在本地主机的情况下可以正常工作,但不能在实时域上工作。

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 Drive 上上传的代码。

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 });
    }
}

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

4

0 回答 0