asp.net处理大文件上传

时间:2022-08-29 16:34:06

asp.net处理大文件上传


    public class HttpUploadHandler : IHttpHandler
{
#region IHttpHandler Members

public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(HttpContext context)
{

HttpWorkerRequest req = (HttpWorkerRequest)((IServiceProvider)context).GetService(typeof(HttpWorkerRequest));

byte[] bts = new byte[2048];



FileStream f = new FileStream("D:\\11.rmvb", FileMode.OpenOrCreate, FileAccess.Write);
int c = req.ReadEntityBody(bts, 2048); // 每次读2048字节

while (c > 0)
{
f.Write(bts, 0, c); // 写入文件
c = req.ReadEntityBody(bts, 2048);
}
f.Close();
context.Response.Write("OK");
context.Response.End();
}

#endregion
}