Large File Upload Using HttpHandler or HttpModule?

空扰寡人 提交于 2019-12-18 18:35:49

问题


I have a webform application. It required to be able to upload large file (100MB). I intended to use httpHandler and httpModule to split the file to chunk.

I also had a look at http://forums.asp.net/t/55127.aspx

But it is a very old post and I've seen some example on the internet using httpHandler.

e.g. http://silverlightfileupld.codeplex.com/

I'm not sure httpModule is still better then httpHandler.

Since httpModule apples to the request of the whole application, and I just want it apply to specify page.

Can anybody explain the shortcoming of httpHandler for large file upload clearly (if it has)? If you know a good example without flash/silverlight , could you post the link here? thx

Edit: Would Like to see some Source Code example.


回答1:


Why not try plupload which has lot of features with many fallbacks and here how it is done.

This is the http handler code:

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


来源:https://stackoverflow.com/questions/10348554/large-file-upload-using-httphandler-or-httpmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!