// base64 转 二进制流(blob) dataURLtoBlob(dataurl) { var arr = dataurl.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime, }); } let file = dataURLtoFile(base64, name);//实例化FormData var formdata = new FormData(); //将文件信息存入formdata,键名为file ll formdata会将文件信息序列化为ajax可识别的数据类型 formdata.append("file", file); $.ajax({ type: "post", url: uploadUrl, data: formdata, ll formdata直接赋值给data processData: false,//formdata已将数据序列化,无需在处理 contentType: false,//formdata无需设置请求头 success: function (res){ resolve(res.data)} });
标签:arr,data,formdata,Base64,js,file,bstr,new,上传 From: https://www.cnblogs.com/xiaoruilin/p/16775390.html