首页> C#> ASP.NET如何报告UploadProgress?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了首页> C#> ASP.NET如何报告UploadProgress?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1956字,纯文字阅读大概需要3分钟。
内容图文
基于此问答
ASP.NET Core 2.0 and Angular 4.3 File Upload with progress
ASP.NET返回HTTP事件-上传进度和最终响应:
[HttpPost, DisableRequestSizeLimit, Route("api/files")]
public async Task UploadFiles()
{
var files = Request.Form.Files; // now you have them
}
Angular接受响应并处理:
this.http.request(req).subscribe(event => {
if (event.type === HttpEventType.UploadProgress)
this.uploadProgress = Math.round(100 * event.loaded / event.total);
else if (event instanceof HttpResponse)
console.log('Files uploaded!');
});
我的问题:
1)上面的ASP.NET代码的哪一部分告诉它必须响应UploadProgress,直到完成上传过程为止?如何知道这是一个需要响应UploadProgress的请求?返回UploadProgress的ASP.NET源代码中的代码在哪里? (https://github.com/aspnet/AspNetCore)
2)总体流程,这是HTTP规范吗?显然,有一条规则,到目前为止我找不到任何文档.
解决方法:
What part of the above ASP.NET code tells that it has to respond UploadProgress
都没有ASP.NET Core不会这样做.
> HttpPost表示您要接受POST请求形式的数据.
> DisableRequestSizeLimit表示您不希望ASP.NET Core阻止文件上传超过预定义的限制(我相信30 MB).
>路线定义路线的URL.
Overall flow, is this an HTTP specification? Clearly, there is a rule and I can’t find any documentation about it so far.
不,不是.这不是必需的.客户端知道成功发送了多少数据,这就是进度的来源.
Angular HTTP库建于XMLHttpRequest左右,其中包含Progress event:
The progress event handler, specified by the updateProgress() function in this example, receives the total number of bytes to transfer as well as the number of bytes transferred so far in the event’s total and loaded fields. However, if the lengthComputable field is false, the total length is not known and will be zero.
Progress events exist for both download and upload transfers. The download events are fired on the XMLHttpRequest object itself, as shown in the above sample. The upload events are fired on the XMLHttpRequest.upload object…
因此,Angular HTTP库仅挂接到本地请求对象的progress事件,然后以更简洁的方式将它们提供给您.
内容总结
以上是互联网集市为您收集整理的首页> C#> ASP.NET如何报告UploadProgress?全部内容,希望文章能够帮你解决首页> C#> ASP.NET如何报告UploadProgress?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。