- 将Base64转为Blob类型
parseFileType: function(basestr, type) {
var text = window.atob(basestr.split(',')[1]);
var buffer = new Uint8Array(text.length);
for (var i = 0; i < text.length; i++) {
buffer[i] = text.charCodeAt(i);
}
var blob = self.getBlob([buffer], type);
return blob;
}
- 获取Blob对象的兼容性写法
getBlob: function(buffer, format) {
try {
return new Blob(buffer, {
type: format
});
} catch (e) {
var bb = new(window.BlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder);
buffer.forEach(function(buf) {
bb.append(buf);
});
return bb.getBlob(format);
}
}
获取到 blob 后可以做图片上传。