您的位置:程序门 -> .net技术 -> web services



如何实现上传和下载100m的文件


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何实现上传和下载100m的文件[已结贴,结贴人:mjdwcn]
发表于:2007-12-25 12:21:41 楼主
如何实现上传和下载100m的文件
发表于:2007-12-25 13:17:411楼 得分:0
up~~~
发表于:2007-12-25 13:37:242楼 得分:0
mark
发表于:2007-12-25 15:28:333楼 得分:0
文件分割与合并
发表于:2007-12-25 15:49:454楼 得分:0
使用bt思想
发表于:2007-12-29 15:05:345楼 得分:20
using   system.web;
public   class   upload
{
public   void   saveupload()
{
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.receivedlength   =   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   num3   =   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.receivedlength   =   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;
}
}
}


快速检索

最新资讯
热门点击