文件上传进度如何报告?

发布于 2024-08-05 18:43:41 字数 290 浏览 3 评论 0原文

我一直在尝试实现ajax风格的文件上传。我想知道我们必须做什么来报告上传进度。我正在尝试在我的 ASP.NET 网页中实现此功能。

我了解我们可以在网页上以 ajax 方式上传文件的机制。我一直在谷歌上搜索很多关于如何显示进度条的信息,但我没有看到正确的解释。但我开始明白,我们必须以某种方式从服务器端管理这个问题。 (参见文件上传进度

任何想法/代码将不胜感激。提前致谢。

I have been trying to implement an ajax-style file upload. I was wondering what we must do to report the uploading progress. I am trying to implement this in my asp.net web page.

I understand the mechanism by which we can upload a file, ajax-style, on a web page. I have been googling a lot about how to show a progress bar, but I don't see proper explanations. But I've come to understand that we have to manage this from the server-side some how. (cf file upload progress)

Any ideas/code would be appreciated. Thanx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2024-08-12 18:43:41

我不知道为什么你想推出自己的,因为有许多使用 Ajax、Flash、Silverlight 等的上传控件。尽管如此,这个概念都是关于查询进度并返回当前状态。 这个人经历了相同的过程并展示了如何他使用 jQuery 构建了一个组件

显示进度需要您的客户端从服务器获取反馈。这意味着重复查询您的服务器以获得进度。使用该信息在您的客户端上显示进度。

在您的服务器上,您不仅必须接受入站文件上传,还必须响应总体进度。如果您获得请求中传递的 Content-Length 标头,那就很容易了;问题在于您无法依赖这些信息。有一些策略可以处理这个问题,但它要求您拥有接受上传文件的代码,因为您必须读取入站位。

此时,您还有其他需要关心的事情,这些事情远远超出了进度条的范围,例如处理 Web 服务器进程中的大文件上传(进程外对您的服务器的危害要小得多。 )

由于涉及的复杂性,我鼓励您找到现有的组件而不是创建自己的组件。

I'm not sure why you want to roll your own, as there are a number of upload controls using Ajax, Flash, Silverlight, etc. Nonetheless, the concept is all about querying for progress and returning the current state. This guy went through the same process and shows how he built a component using jQuery.

Displaying progress requires your client getting feedback from your server. This means repetitive queries to your server to get progress. Display the progress on your client using that information.

On your server, you have to not only accept the inbound file upload but also respond with the aggregate progress. It's easy if you get the Content-Length header passed along in the request; the problem lies in that you won't be able to rely on having that information. There are strategies for dealing with this, but it requires you to have code that accepts the uploaded file as you're going to have to read the inbound bits.

At this point, you have other things to care about that are well beyond the scope of a progress bar, such as dealing with large file uploads in-process of your web server (out-of-process is much less detrimental to your server.)

Because of the complexities involved, I would encourage you to find an existing component instead of creating your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文