关键代码:
// 将base64 的数据弄到form表单中 // 将base64 的代码转化为二进制 let bytes = window.atob(crop_base64.split(',')[1]); let ab = new ArrayBuffer(bytes.length); let ia = new Int8Array(ab); for (let i = 0; i < bytes.length; ++ i) { ia[i] = bytes.charCodeAt(i); } let blob = new Blob([ia], {type: 'image/jpeg'}); let file_name = new Date(); blob.name = file_name + '.jpg'; blob.lastModifiedDate = file_name; console.log(blob); let form = document.getElementById('crop_form'); let form_data = new FormData(form); // 将数据弄到 form 表单中 form_data.append('crop_file', blob, file_name);