Javascript Base64转Blob


转换方法

function dataURLtoFile(dataurl, filename) {
    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); } var theBlob = new Blob([u8arr], {type: mime }); theBlob.lastModifiedDate =new Date(); theBlob.name = filename; return theBlob; }

图片上传

var images = new FormData();
images.append('images[]', dataURLtoFile(base64, filename), filename); $.ajax({ url: 'uploadImage', async: false, type: 'post', data: images, processData: false, contentType: false, success: function(data){ //TODO  } });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM