我想在将文件上传到 Amazon S3 时在我的网页上的进度条中显示文件上传进度......
在我的网页上,我从文件输入中选择一个文件,该文件通过 Ajax POST 请求调用我的 Controller 。
在 Controller 中,我从发布的请求中提取文件。
var hpf = Request.Files[1];
然后我调用一个使用 AmazonS3Client 的方法..
UploadVideoMultiPart(hpf.InputStream,fileName)
上述方法完美地完成了到 S3 的上传,并在此过程中重复发送上传的字节数。
public static void UploadPartProgressEventCallback(object sender, StreamTransferProgressArgs e)
{// Process event.
Var progress = (string.Format("{0}/{1}", e.TransferredBytes, totalContentLength));
}
例子:
TransferredBytes 总字节数
8778 152652556
2562 152652556
如何在不停止上传线程的情况下将数据从 UploadPartProgressEventCallback 发送回浏览器。
如果我能得到这些数据,我就能更新我的进度条。
最佳答案
You Need something to communicate between your Server to Client
SignalR在这种情况下,SignalR 是您的救星,您可以将内容从服务器端推送到客户端。
完整文档在这里SignalR@GitHub
你可以关注这些
web resources还有
(假设您已经通过上面的链接)
现在回到你的需求,
you can even hook SignalR broadcast ie can call client method and manage groups outside the Hub class
这里有一个很好解释的例子 In this Example
虽然不熟悉会是新的api,但是相信我,掌握它不会花很多时间,
关于c# - 如何在进度条中显示文件上传进度 - Amazon S3 bucket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32790689/