首页 > 解决方案 > 使用拆分功能时出错:未捕获的类型错误:无法读取 null 的属性“1”

问题描述

这段代码有什么问题?有人可以帮助我吗?

export class Base64 {

    static getMimeType(urlBase64){

        let regex = /^data:(.+);base64,(.*)$/;
        let result = urlBase64.match(regex);
        return result[1];

    }

    static toFile(urlBase64){

        let mimeType = Base64.getMimeType(urlBase64);
        let ext = mimeType.split('/')[1];
        let filename = `file${Date.now()}.${ext}`;

        return fetch(urlBase64)
            .then(res => { return res.arrayBuffer(); })
            .then(buf => { return new File([buf], filename, { type: mimeType }); });

    }

}

出现此错误:TypeError: Cannot read property '1' of null

标签: javascript

解决方案


推荐阅读