2012-04-27 27 views
0

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

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

但它是一个很老的帖子,我已经看到了使用的HttpHandler在互联网上的一些例子。

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

我不确定httpModule比httpHandler更好。

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

有人可以解释一下httpHandler对于大文件上传的缺点吗(如果有的话)? 如果你知道一个没有flash/silverlight的好例子,你可以在这里发布链接吗? thx

编辑:希望看到一些源代码的例子。

+0

http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx – 2012-04-27 09:58:47

+0

@KamranPervaiz thx我读过那一个。我更喜欢查看一些源代码示例。 – 2012-04-27 10:03:03

回答

1

为什么不尝试plupload它有许多功能与许多fallback和在这里是如何完成的。

这是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 
+0

无法找到块读取部分,似乎plupload不支持HTML4,THX无论如何。 – 2012-04-27 10:10:24

+0

它支持HTML4.from API文档http://www.plupload.com/plupload/docs/api/index.html#class_plupload.runtimes.Html4.html – coder 2012-04-27 10:11:45

+0

出于兴趣,为什么将缓冲区设置为输入流长度减1? – 2013-02-12 03:03:37