我正在使用Google.Apis.Driver.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);
}
这就是您想要的:
await request.UploadAsync(ctsUpload);