c# - Google drive api v3 c# Uploadprogress trigger during file Upload
问题描述
我正在使用 Drive api 上传文件。上传工作正常,进度也在触发。但在上传完成后触发。我希望在上传和响应网页时同时触发进度。试过这段代码。
protected async void Button1_Click(object sender, EventArgs e)
{
await RunDownloadAsync();
}
private async Task RunDownloadAsync()
{
Google.Apis.Drive.v3.Data.File asd = new Google.Apis.Drive.v3.Data.File();
asd = await Task.Run(() => upload(path, filename));
}
public async Task<Google.Apis.Drive.v3.Data.File> upload(string _fileloc, string filename)
{
request = service.Files.Create(fileMetadata, stream, GetMimeType(_fileloc));
// request = service.Files.Create();
request.Fields = "*";
request.ChunkSize = 262144;
request.ProgressChanged += (IUploadProgress)=> Request_ProgressChanged1(IUploadProgress);
await Task.Run(()=> request.UploadAsync());
}
// return request.ResponseBody;
// var aaaa = request.ResponseBody;
return request.ResponseBody;
}
private void Request_ProgressChanged1(IUploadProgress obj)
{
double pc = (obj.BytesSent * 100) / FileUpload1.PostedFile.ContentLength;
File.AppendAllText(@"d:\date.txt", DateTime.Now.ToString("hh:mm:ss.fff") + obj.Status.ToString() + " - " + obj.BytesSent + "____" + pc.ToString("0.00") + Environment.NewLine);
Label2.Text += DateTime.Now.ToString("hh:mm:ss.fff") + obj.Status.ToString() + " - " + obj.BytesSent + "____" + pc + "<br>";
Response.Write(DateTime.Now.ToString("hh:mm:ss.fff") + obj.Status.ToString() + " - " + obj.BytesSent + "____" + pc + "<br>");
// close the stream
// HttpContext.Current.Response.Write(string.Format(obj.Status + " " + obj.BytesSent));
// HttpContext.Current.Response.Write(obj.BytesSent.ToString());
}
}
}
解决方案
推荐阅读
- php - 如果php中的多维数组如何回显
- python - keras 加载模型并测试模型 seq2seq
- google-cloud-platform - 谷歌云更改sudo密码
- spring - Spring Boot 电子邮件微服务在 Swarm 模式下不起作用
- jpa - 从单向多对多关系中删除,其中 Cascade.Remove 不是一个选项
- java - == 运算符是否比 equals() 更快?
- mysql - 获取匹配记录的总和,然后使用 JPA 更新这些记录
- spring-security - spring security oauth2 客户端提供者 issuer-uri 上的自签名证书
- android - 如何将 SQLite GridView 中的图像放入 ImageView?
- json - 如何在 JSON 文件中写入所有参数 jenkins