




已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
用HTTP協(xié)議上傳大文件也許是個不好辦的問題。主要是它的不連續(xù)性,使得上傳文件感覺很“危險”。特別是很大的文件(幾百MB甚至是上G的文件),心里總覺得不踏實,一不小心就會出現(xiàn)問題,而一但出現(xiàn)問題就無法繼續(xù)上傳,這是很郁悶的。后來在一些網(wǎng)站上找到一些上傳文件的組件,但都是要用到一些COM組件。至于后來的ASP.net下上傳大文件的解決方案,我也做過一個組件,后來發(fā)現(xiàn)根本就不用自己寫什么組件,利用ASP.net自己的上傳方法也可以解決大文件上傳,真是郁悶的要死了?;叵胫?,決定用Web service來做一個文件上傳,還是利用HTTP協(xié)議,這樣不用在服務器上做太多的變動,而客戶端也簡單。首先是解決方案的設計:因為Web service可以利用SOAP來傳遞數(shù)據(jù),而且可以傳遞十進制數(shù)據(jù),因此可以想到,在服務上公開一個方法,參數(shù)可以是byte數(shù)組,這樣可以把文件分塊的上傳到服務器。這一解決方法我做過,但速度很慢。后來在MS上找到一些文章,用MS最新公開的服務組件上傳文件,速度快了很多。而自己所要做的就是組織一些安全性的問題。部份代碼:Upload Instanceusing System;using System.IO;using Microsoft.Web.Services2;using Microsoft.Web.Services2.Dime;namespace Webb.WAVE.WinUpload / / Summary description for Controls. / public class UploadInstance2 #region Fields private string m_GUID; private DateTime m_uploadTime; private long m_fileLength; private long m_currentPoint; private string m_pathOnserver; private long m_userID; #endregion #region Properties public long UserID getreturn this.m_userID; setthis.m_userID=value; public string GUID getreturn this.m_GUID; setthis.m_GUID=value; public DateTime UploadTime getreturn this.m_uploadTime; set public long FileLength getreturn this.m_fileLength; setthis.m_fileLength=value; public long CurrentPoing getreturn this.m_currentPoint; setthis.m_currentPoint=value; public string PathOnServer getreturn this.m_pathOnserver; setthis.m_pathOnserver=value; public string FullPathOnServer get if(this.m_GUID!=string.Empty&this.m_pathOnserver!=string.Empty) return Path.Combine(this.m_pathOnserver,this.m_GUID+.rem); else return string.Empty; public string FileName get if(this.m_GUID!=string.Empty) return this.m_GUID+.rem; else return string.Empty; #endregion public UploadInstance2() this.m_GUID = System.Guid.NewGuid().ToString(); this.m_uploadTime = System.DateTime.Now; this.m_currentPoint = 0; this.m_fileLength = 0; this.m_pathOnserver = string.Empty; public UploadInstance2(string i_path,string i_GUID,long i_fileLength) string m_fullPath = Path.Combine(i_path,i_GUID); if(!File.Exists(m_fullPath) return; this.m_GUID = i_GUID; this.m_uploadTime = System.DateTime.Now; this.m_pathOnserver = i_path; FileInfo m_fileInfo = new FileInfo(m_fullPath); this.m_currentPoint = m_fileInfo.Length; this.m_fileLength = i_fileLength; public bool UploadData(byte i_data, long i_currentPoint, int i_dataSize) string m_fullPath = this.FullPathOnServer; if(!File.Exists(m_fullPath)&this.m_currentPoint!=0)return false; long m_filePoint = new FileInfo(m_fullPath).Length; if(m_filePoint!=i_currentPoint) return false; FileStream m_fileStream = new FileStream(m_fullPath,FileMode.Append); m_fileStream.Write(i_data,0,i_dataSize); m_fileStream.Close(); return true; public void AbandantUpload() string m_fullPath = this.FullPathOnServer; tryFile.Delete(m_fullPath); catch public void CreateFile() string m_fullPath = this.FullPathOnServer; if(!File.Exists(m_fullPath) File.Create(m_fullPath).Close(); else try File.Delete(m_fullPath); catch File.Create(m_fullPath).Close(); 上傳過程:#region UploadProcess public void UploadProcess() DateTime m_start = DateTime.Now; this.textBox_OutMsg.AppendText(Initialize uploadrn); if(this.m_upload=null|this.m_uploadGUID=null|this.m_uploadGUID=string.Empty) this.textBox_OutMsg.AppendText(Upload instance id error or login to the server faildrn); this.textBox_OutMsg.AppendText(Upload faild.rn); return; this.textBox_OutMsg.AppendText(Open filern); if(this.m_filePath=null|this.m_filePath=string.Empty|!File.Exists(this.m_filePath) this.textBox_OutMsg.AppendText(Open file errorrn); this.textBox_OutMsg.AppendText(Upload faild.rn); return; FileInfo m_fileInfo = new FileInfo(this.m_filePath); FileStream m_fs = new FileStream(this.m_filePath, FileMode.Open, FileAccess.Read); this.textBox_OutMsg.AppendText(Start upload filern); int m_buffer = 10; /KBytes long m_currentPoint = 0; long m_fileLength = m_fileInfo.Length; bool m_uploadResult = false; byte m_data = new bytem_buffer*1024; long m_readBytes = m_fs.Read(m_data, 0, m_buffer*1024); this.UploadProcessBar.Maximum = 100; this.UploadProcessBar.Minimum = 0; while(m_readBytes0) MemoryStream m_memoryStream = new MemoryStream(m_data, 0,(int)m_readBytes); DimeAttachment dimeAttach = new DimeAttachment(image/gif, TypeFormat.MediaType, m_memoryStream); this.m_upload.RequestSoapContext.Attachments.Add(dimeAttach); m_uploadResult = this.m_upload.UploadFileData(this.m_uploadInstance,m_currentPoint,m_readBytes); if(m_uploadResult) m_currentPoint +=m_readBytes; m_readBytes = m_fs.Read(m_data,0,m_buffer*1024); / this.textBox_OutMsg.AppendText(Uploading:+m_currentPoint.ToString()+/+m_fileLength.ToString()+rn); this.UploadProcessBar.Value = (int)(m_currentPoint*100/m_fileLength); this.label_outPercent.Text = this.UploadProcessBar.Value.ToString()+%; else this.textBox_OutMsg.Ap
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工業(yè)管道的維護與檢修方法
- 工作中的自我管理與激勵方法
- 工業(yè)設計與科技創(chuàng)新的融合發(fā)展
- 工業(yè)風味的文化創(chuàng)意街區(qū)轉(zhuǎn)型實踐
- 工業(yè)風建筑設計理念與實踐
- 工業(yè)設計產(chǎn)業(yè)園在服務領(lǐng)域的應用
- 工程中的液壓傳動系統(tǒng)設計與分析
- 工廠企業(yè)消防安全管理體系
- 工程機械設備的技術(shù)改造與升級
- 工程教育中數(shù)據(jù)科學的課程設計
- 2024年山東省高中學業(yè)水平合格考生物試卷試題(含答案詳解)
- 電影敘事與美學智慧樹知到期末考試答案章節(jié)答案2024年南開大學
- YYT 0663.3-2016 心血管植入物 血管內(nèi)器械 第3部分:腔靜脈濾器
- 【專業(yè)版】短視頻直播電商部門崗位職責及績效考核指標管理實施辦法
- SOHO-VD 收獲變頻器手冊
- 修理廠大修發(fā)動機保修合同
- 富血小板血漿(PRP)簡介
- MOOC 網(wǎng)絡技術(shù)與應用-南京郵電大學 中國大學慕課答案
- 四年級下冊數(shù)學教案-8.1確定位置丨蘇教版
- 乳粉大數(shù)據(jù)與智能制造
- 《初三中考動員會》課件
評論
0/150
提交評論