In this project, a large file upload is used, and the number of files to be uploaded is more than 100 MB. The component found that many of them used two controls: aspnetupload 2.0 and Lion. Web. uploadmodule. In addition, they thought about its blog. The way mentioned in http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx The two controls use the implicit httpworkerrequest method to read data from the pipe created for ASP. NET by using its getpreloadedentitybody and readentitybody method. Chris Hynes provides us with such a solution (using httpmodule) that allows you to upload large files and display the upload progress in real time. Lion. Web. uploadmodule and aspnetupload both use this solution. When the leaflet file is used, the two software methods are the same, inheriting the httpmodule Httpapplication application1 = sender as httpapplication; Httpworkerrequest request1 = (httpworkerrequest) (iserviceprovider) httpcontext. Current). getservice (typeof (httpworkerrequest )); Try { If (application1.context. Request. contenttype. indexof ("multipart/form-Data") <=-1) { Return; } // Check the hasentitybody If (! Request1.hasentitybody ()) { Return; }Int num1 = 0; Timespan span1 = datetime. Now. Subtract (this. begintime ); String text1 = application1.context. Request. contenttype. tolower (); Byte [] buffer1 = encoding. ASCII. getbytes ("/R/n --" + text1.substring (text1.indexof ("boundary =") + 9). tochararray ()); Int num2 = convert. toint32 (request1.getknownrequestheader (11 )); Progress progress1 = new progress (); Application1.context. Items. Add ("filelist", new hashtable ()); Byte [] buffer2 = request1.getpreloadedentitybody (); Num1 + = buffer2.length; String text2 = This. analysepreloadedentitybody (buffer2, "uploadguid "); If (text2! = String. Empty) { Application1.context. Items. Add ("lionsky_uploadmodule_uploadguid", text2 ); } Bool flag1 = true; If (num2> This. uploadfilelength () & (0> span1.totalhours) | (span1.totalhours> 3 ))) { Flag1 = false; } If (0> span1.totalhours) | (span1.totalhours> 3 )) { Flag1 = false; } String text3 = This. analysepreloadedentitybody (buffer2, "uploadfolder "); Arraylist list1 = new arraylist (); Requeststream stream1 = new requeststream (buffer2, buffer1, null, requeststream. filestatus. Close, requeststream. readstatus. noread, text3, flag1, application1.context, String. Empty ); List1.addrange (stream1.readbody ); If (text2! = String. Empty) { Progress1.filelength = num2; Progress1.ededlength = num1; Progress1.filename = stream1.originalfilename; Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count; Application1.application ["_ uploadguid _" + text2] = progress1; } If (! Request1.isentireentitybodyispreloaded ()) { Byte [] buffer4; Arraylist list2; Int Number3 = 204800; Byte [] buffer3 = new byte [num3]; While (num2-num1)> = num3) { If (! Application1.context. response. isclientconnected) { This. clearapplication (application1 ); } Num3 = request1.readentitybody (buffer3, buffer3.length ); Num1 + = num3; List2 = stream1.contentbody; If (list2.count> 0) { Buffer4 = new byte [list2.count + buffer3.length]; List2.copyto (buffer4, 0 ); Buffer3.copyto (buffer4, list2.count ); Stream1 = new requeststream (buffer4, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename ); } Else { Stream1 = new requeststream (buffer3, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename ); } List1.addrange (stream1.readbody ); If (text2! = String. Empty) { Progress1.ededlength = num1; Progress1.filename = stream1.originalfilename; Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count; Application1.application ["_ uploadguid _" + text2] = progress1; } } Buffer3 = new byte [num2-num1]; If (! Application1.context. response. isclientconnected & (stream1.fstatus = requeststream. filestatus. Open )) { This. clearapplication (application1 ); } Num3 = request1.readentitybody (buffer3, buffer3.length ); List2 = stream1.contentbody; If (list2.count> 0) { Buffer4 = new byte [list2.count + buffer3.length]; List2.copyto (buffer4, 0 ); Buffer3.copyto (buffer4, list2.count ); Stream1 = new requeststream (buffer4, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename ); } Else { Stream1 = new requeststream (buffer3, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename ); } List1.addrange (stream1.readbody ); If (text2! = String. Empty) { Progress1.receivedlength = num1 + buffer3.length; Progress1.filename = stream1.originalfilename; Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count; If (flag1) { Progress1.uploadstatus = progress. uploadstatusenum. Uploaded; } Else { Application1.application. Remove ("_ uploadguid _" + text2 ); } } } Byte [] buffer5 = new byte [list1.count]; List1.copyto (buffer5 ); This. populaterequestdata (request1, buffer5 ); } Catch (exception exception1) { This. clearapplication (application1 ); Throw exception1; } |