Need to use
Slice () method
Reference
Http://www.w3school.com.cn/jsref/jsref_slice_array.asp
The front-end HTML usage tag is
Type=file input tag, you can directly select File upload
Js:
function () { varFile = $ ("#SelectImageFile") [0].files[0]; varFileName =File.name; varFilesplitsize = 1 * 1024 * 1024;//file Fragment size 5M varSize =file.size; varPostURL = Postweburl;//Background method address for uploading files varFormData =NewFormData (); varIndex1 = Filename.lastindexof (".")); varIndex2 =filename.length; varsuffix = filename.substring (index1, INDEX2);//suffix name //If you need to limit the suffix name, you can write this if(Suffix! = ". rar" && suffix! = ". zip" && suffix! = ". 7z") {msg ("The uploaded image information must be. rar,.zip,.7z format"); } Else{formdata.append ("File", File.slice (start, start +filesplitsize)); Formdata.append ("Name", FileName); $.ajax ({url:posturl, type:' POST ', Data:formdata,//tell jquery not to process the data sentProcessData:false,//tell jquery not to set the Content-type request headerContentType:false, Beforesend:function () { //Console.log ("In progress, please wait"); }, //multipart upload, 1-5 upload successful, then upload 6-11, and so on, after successful, give a hint, before success, will always show the upload progressSuccessfunction(data) {$ ("#process"). Show ();//Progress bar Display if(Start + filesplitsize >=size) { $("#spnProcessShow"). CSS ("width", "100%"); $("#spnProcessText"). HTML ("Upload completed, uploaded 100%"); } Else{Start+=filesplitsize; Percentage= Math.Round (start/size * 100); $("#spnProcessShow"). CSS ("width", Percentage + "%")); $("#spnProcessText"). HTML ("uploading, uploaded" + Percentage + "%")); }}, Error:function(data) {Start= 0; $("#process"). Hide ();//Hide Progress bar$ ("#spnProcessShow"). CSS ("width", "0%"); $("#lblMsg"). HTML ("image upload failed"); } }); } }
Method of front-end accept file Call background upload file