国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 上傳大文件解決方案

2024-07-10 13:06:24
字體:
來源:轉載
供稿:網友

這次在項目中,用到了大文件上傳,要上傳的文件有100多m,于是研究現在國內使用的大文件上傳的
組件發現用的比較多的有兩個控件aspnetupload 2.0和lion.web.uploadmodule,另外還有思歸在它的博客
堂中所說的辦法 http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx
   兩個控件的方法是:利用隱含的httpworkerrequest,用它的getpreloadedentitybody 和 readentitybody方法從iis為asp.net建立的pipe里分塊讀取數據。chris hynes為我們提供了這樣的一個方案(用httpmodule),該方案除了允許你上傳大文件外,還能實時顯示上傳進度。
    lion.web.uploadmodule和aspnetupload 兩個.net組件都是利用的這個方案。
   當上傳單文件時,兩個軟件的方法是一樣的,繼承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.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;
   }


  而思歸所說的方法使用mime也能上傳大文件,在以下地址下載
  http://krystalware.com/files/slickupload.zip
  不過覺得的思歸的方法容易很多

相關文章:
讓asp.net默認的上傳組件支持進度條反映
http://blog.joycode.com/dotey/archive/2005/06/12/53557.aspx // 寶玉
http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx // 思歸
http://www.cnblogs.com/bestcomy/archive/2004/06/09/14267.aspx // bestcomy
http://krystalware.com/wiki/default.aspx/krystalwiki.uploadspike1
http://www.blueidea.com/tech/program/2005/2997.asp //ftp
通過web services上傳和下載文件
http://dotnet.aspx.cc/showdetail.aspx?id=6381bd5f-51f3-4339-4239-1328564a1b2a
上傳組件是如何不受settimeout限制的?
http://www.ietf.org/rfc/rfc1867.txt?number=1867

下載
http://support.microsoft.com/default.aspx?scid=kb;en-us;812406&product=aspnet

上傳源代碼下載:
openlabupload.rar

  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 日土县| 顺义区| 东安县| 莱州市| 原平市| 深水埗区| 泗洪县| 宁明县| 丹凤县| 阳曲县| 彭山县| 库尔勒市| 金山区| 万安县| 四川省| 紫阳县| 临桂县| 确山县| 辽阳市| 安乡县| 安仁县| 福州市| 平湖市| 四会市| 清丰县| 建湖县| 莱西市| 旬邑县| 和硕县| 甘谷县| 女性| 周口市| 壶关县| 普兰店市| 临沂市| 嘉义县| 定安县| 皮山县| 新蔡县| 永丰县| 锡林浩特市|