没时间解释了,快上车...
前端js:upload=function () { if(window.FormData) { var fileslist=$("input[type=‘file‘]"); if(fileslist.length>0) { if(fileslist.get(0).files[0]!=undefined) { var Thefile=fileslist.get(0).files[0]; UpdateProgressBar(0,"正在压缩..."+"0%"); var zip=new JSZip(); zip.file(Thefile.name, Thefile); zip.generateAsync({type:"Blob",compression: "DEFLATE",},function updateCallback(metadata){UpdateProgressBar(metadata.percent.toFixed(2),"正在压缩..."+metadata.percent.toFixed(2)+"%");}).then(function(content) //级别:1最快,9最小 { var file = new File([content],‘upload.zip‘,{type: "zip"}); var dict=new FormData(); dict.append("fileContent",file); var xhr=new XMLHttpRequest(); xhr.open(‘POST‘, USERNAME+";"+obj+";"+date+";"+startTime+";"+endTime,true); xhr.upload.onprogress=function(event) { if(event.lengthComputable) { UpdateProgressBar((event.loaded / event.total * 100 | 0),"正在上传..."+(event.loaded / event.total * 100 | 0)+"%"); if((event.loaded / event.total * 100 | 0)>=100) { hideUploadProgressBar(); } } } xhr.send(dict); }); } } } }
有一说一:博客园这些个编辑器是要逼死强迫症吗?
后台c# HttpListenerContext nowContext = MainHttpListener.EndGetContext(ar); HttpListenerRequest request = context.Request; MemoryStream ms = new MemoryStream(); request.InputStream.CopyTo(ms); var buff = ms.ToArray(); var msg = System.Text.Encoding.ASCII.GetString(buff); sec2 = msg; int index = sec2.IndexOf("PK");//压缩包文件PK开头 string front = sec2.Substring(0, index); List<byte> A = new List<byte>(); A.AddRange(buff); List<byte> B = new List<byte>(); B.AddRange(System.Text.Encoding.ASCII.GetBytes(front)); A.RemoveRange(0, B.Count); byte[] writeBytes = A.ToArray();//此为文件字节,File.WriteAllByte()存为zip,便可以了,可正常解压; ConsoleUserColor.SetColorText("文件接收成功");