0

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.

Jasonw
  • 5,054
  • 7
  • 43
  • 48
Dan An
  • 424
  • 9
  • 27

1 Answers1

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
coder
  • 13,002
  • 31
  • 112
  • 214
  • Cannot find read to chunk part and seems plupload doesn't support HTML4, thx anyway. – Dan An Apr 27 '12 at 10:10
  • it supports HTML4.from the API documentation http://www.plupload.com/plupload/docs/api/index.html#class_plupload.runtimes.Html4.html – coder Apr 27 '12 at 10:11
  • Out of interest why is the buffer set to the input stream length minus 1? – Tom W Hall Feb 12 '13 at 03:03