第一步转为blob对象没问题:
function dataURItoBlob (base64Data) {
var byteString;
if (base64Data.split(',')[0].indexOf('base64') >= 0){
byteString = atob(base64Data.split(',')[1]);
}else{
byteString = unescape(base64Data.split(',')[1]);
}
var mimeString = base64Data.split(',')[0].split(':')[1].split(';')[0];
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], {type:mimeString});
}
但是第二步将blob对象放入到formdata中感觉不对:
var fd = new FormData(obj);
var blob = dataURItoBlob (base64,'mimeString');
fd.append("files[]", blob);
当我用ajax上传给后台的时候,报错405
相关分类