Asp.Net高级文件上传
在 mvc3 站点上使用标准 时,您可以通过创建
HttpPostedFile
并将表单设置为 enctype="multipart/form-data"
这种方法的问题之一是请求不会完成,并且不会传递给您的操作方法,直到文件已上传。
我想在该文件上传到服务器时对该文件执行一些操作。基本上我想异步接收数据,然后以编程方式逐字节处理数据。
为了完成上述任务,我想您可能需要在 HttpModule 或自定义 HttpHandler 中处理这部分请求。我熟悉这些事情的工作原理,但我不熟悉异步接收文件上传数据的方法。
我知道这是可能的,因为我过去曾使用过这样做的第三方组件(通常这样他们就可以报告上传进度,或将数据缓存到磁盘以避免 iis/asp.net 内存限制)。不幸的是,我使用的所有组件都是闭源的,所以我无法窥视内部并了解它们在做什么。
我不是在寻找代码,但是有人可以帮我指出正确的方向吗?
When using a standard <input type="file" />
on an mvc3 site, you can receive the file in your action method by creating an input parameter of type HttpPostedFile
and setting the form to enctype="multipart/form-data"
One of the problems of this approach is that the request does not complete and is not handed off to your action method until the entire contents of the file have been uploaded.
I would like to do some things to that file as it is being uploaded to the server. Basically i want to asynchronously receive the data as it comes in and then programmatically handle the data byte by byte.
To accomplish the above I imagine you will need to handle this part of the request in an HttpModule or custom HttpHandler perhaps. I am familiar with how those things work, but I am not familiar with the method of receiving the file upload data asynchronously as it comes in.
I know this is possible because I have worked with 3rd party components in the past that do this (normally so they can report upload progress, or cache the data to disk to avoid iis/asp.net memory limitations). Unfortunately all the components I have used are closed source so I can't peek inside and see what they are doing.
I am not looking for code, but can someone get me pointed in the right direction here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 WCF 服务,您可以向服务发送文件流或从服务发送文件流。
这是我使用的服务端接收代码:
如果这看起来像您想要的,请查看 CodeProject 文件传输进度。它涉及到我的代码大致基于的许多细节。
Using a WCF service you can send file streams to and from your service.
Here is the service side receive code I use:
If that looks like what you want, check out the CodeProject File Transfer Progress. It goes into a lot of detail that my code is loosely based on.