javascript BLOB 图片预览

使用方式:
一、使用URL.createObjectURL(file)​​​​预览图片
objectURL = URL.createObjectURL(blob);

示例

<input type="file" id="btn" accept="image/*" value="点击上传" />
<img id="img"/>

btn.addEventListener('change',function(){
    let file = this.files[0];
    // 进一步防止文件类型错误
    if(!/image/w+/.test(file.type)){  
        alert("看清楚,这个需要图片!");  
        return false;  
    }  
    img.src = URL.createObjectURL(file)
})
原文地址:https://www.cnblogs.com/xuan52rock/p/13516172.html