首页 文章

使用HttpHandler或HttpModule进行大文件上传?

提问于
浏览
0

我有一个webform应用程序 . 它需要能够上传大文件(100MB) . 我打算使用httpHandler和httpModule将文件拆分为 chunk .

我也看了http://forums.asp.net/t/55127.aspx

但这是一篇非常古老的帖子,我在互联网上看到了一些使用httpHandler的例子 .

例如http://silverlightfileupld.codeplex.com/

我不确定httpModule是否比httpHandler更好 .

由于httpModule苹果对整个应用程序的请求,我只是希望它适用于指定页面 .

任何人都可以清楚地解释 shortcoming of httpHandler for large file upload (如果有的话)?如果你知道没有flash / silverlight的好例子,你可以在这里发布链接吗?谢谢

编辑:想看一些 Source Code 的例子 .

1 回答

  • 1

    为什么不尝试plupload,它具有许多具有许多后备功能的功能,以及如何完成 .

    这是http处理程序代码:

    Imports System
    Imports System.IO
    Imports System.Web
    
    
    Public Class upload : Implements IHttpHandler
    
    
        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
            Dim chunk As Integer = If(context.Request("chunk") IsNot Nothing, Integer.Parse(context.Request("chunk")), 0)
            Dim fileName As String = If(context.Request("name") IsNot Nothing, context.Request("name"), String.Empty)
    
            Dim fileUpload As HttpPostedFile = context.Request.Files(0)
    
            Dim uploadPath = context.Server.MapPath("~/uploads")
            Using fs = New FileStream(Path.Combine(uploadPath, fileName), If(chunk = 0, FileMode.Create, FileMode.Append))
                Dim buffer = New Byte(fileUpload.InputStream.Length - 1) {}
                fileUpload.InputStream.Read(buffer, 0, buffer.Length)
    
                fs.Write(buffer, 0, buffer.Length)
            End Using
    
            context.Response.ContentType = "text/plain"
            context.Response.Write("Success")
        End Sub
    
        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
    
    End Class
    

相关问题