0
votes

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
@KamranPervaiz thx i've read that one. I prefer to view some source code example.Dan An

1 Answers

1
votes

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