谷歌驱动器api,不会上传异步

时间:2016-08-01 16:00:13

标签: c# google-api google-api-dotnet-client

我正在使用Google.Apis.Drive.v3来管理一些文件。我的问题是我只能以同步方式上传文件。 这个异步上传只是不上传文件:

    var service = GetService(i_user_credential, i_application_name);

    var fileMetadata = new Google.Apis.Drive.v3.Data.File();
    fileMetadata.Name = i_file_name;
    fileMetadata.Parents = new List<string> { i_folder_id };

    FilesResource.CreateMediaUpload request;
    CancellationToken ctsUpload = new CancellationToken(); 

    using (var stream = new System.IO.FileStream(i_file_path, System.IO.FileMode.Open))
    {
        request = service.Files.Create(
            fileMetadata, stream, i_file_type);
        request.Fields = "id";
        request.UploadAsync(ctsUpload);
    }

1 个答案:

答案 0 :(得分:0)

这就是您想要的:

await request.UploadAsync(ctsUpload);