) {
console
.
log
(
this
.
files
[
0
])
file2DataUrl
(
this
.
files
[
0
],
function
(
img
) {
console
.
log
(img)
将base64的dataURL转为Blob对象
function 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
dataURLtoBlob('data:image/png;base64,XXXXXXXX')
将Blob对象转为File对象
function blobtoFile({ type } = blob) { return new File([blob], '自定义文件名称', { type })}//调用上面的dataURLtoBlob方法生成测试的dataURLvar blob = dataURLtoBlob('data:image/png;base64,XXXXXXXX');console.log(blobtoFile(blob))
复制代码