記一次jquery file upload的斷點續傳的問題的糾結曆程

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   檔案   資料   

相關參考:http://www.cnblogs.com/ASPNET2008/p/3360427.html

開始打算做斷點續傳的時候直接拷貝的這一串代碼,放到我的項目裡面之後Request.Files中的Filename擷取到的一直是"blob",

然後我就拖啊拖了很久,後來打算放棄掉不做了,昨天測試Jquer File Upload這個上傳組件的時候發現超過2G的檔案死都傳不上去!

1   <system.web>2         <httpRuntime maxRequestLength="2147483647" executionTimeout="3600"/>3         <compilation debug="true" targetFramework="4.0"/>4     <customErrors mode="Off"/>5     </system.web>

後來發現設定完之後支援的最大檔案大小就差不多2G左右的樣子,然後我又重新去做檔案的斷點續傳!希望可以搞定這個問題!

但是!還是擷取不到FileName!!!!

然後!我就換了一種方式用了Request.Headers["X-File-Name"],果然擷取到FileName了!

但是!saveas裡面又得不到content-range的值了!

又是一番糾結之後,發現是因為我用的外掛程式的版本太低了。。然後!我又去官網上下載了最新版本的外掛程式!

果然!不存在FileName和content-range擷取不到的問題了!

又但是!超出2G的檔案2G以上的部分還是不能上傳!也是敗給那個博主了!根本沒有考慮過超大檔案的問題嘛!

 1 private void SaveAs(string saveFilePath, HttpPostedFile file) 2 { 3     long lStartPos = 0; 4     int startPosition = 0; 5     int endPosition = 0; 6     var contentRange=HttpContext.Current.Request.Headers["Content-Range"]; 7     //bytes 10000-19999/1157632 8     if (!string.IsNullOrEmpty(contentRange)) 9     {10         contentRange = contentRange.Replace("bytes", "").Trim();11         contentRange = contentRange.Substring(0, contentRange.IndexOf("/"));12         string[] ranges = contentRange.Split(‘-‘);13         startPosition = int.Parse(ranges[0]);14         endPosition = int.Parse(ranges[1]);15     }16     System.IO.FileStream fs;17     if (System.IO.File.Exists(saveFilePath))18     {19         fs = System.IO.File.OpenWrite(saveFilePath);20         lStartPos = fs.Length;21          22     }23     else24     {25         fs = new System.IO.FileStream(saveFilePath, System.IO.FileMode.Create);26         lStartPos = 0;27     }28     if (lStartPos > endPosition)29     {30         fs.Close();31         return;32     }33     else if (lStartPos < startPosition)34     {35         lStartPos = startPosition;36     }37     else if (lStartPos > startPosition && lStartPos < endPosition)38     {39         lStartPos = startPosition;40     }41     fs.Seek(lStartPos, System.IO.SeekOrigin.Current);42     byte[] nbytes = new byte[512];43     int nReadSize = 0;44     nReadSize = file.InputStream.Read(nbytes, 0, 512);45     while (nReadSize > 0)46     {47         fs.Write(nbytes, 0, nReadSize);48         nReadSize = file.InputStream.Read(nbytes, 0, 512);49     }50     fs.Close();          51 }

注意13行!14行!檔案位元組超出2G的時候int已經超出範圍!

就是要把變數設定成long的資料類型嘛!

終於,一個多月過去了。。。

還是被我搞定了啊哈哈哈哈!!!!!

 

記一次jquery file upload的斷點續傳的問題的糾結曆程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.