javascript - 使用拆分功能时出错:未捕获的类型错误:无法读取 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
解决方案
推荐阅读
- c# - 查询具有最小属性的一个孩子的父母
- javascript - 如何在 JS 中从 iframe 转换到页面?
- r - 如何将 difftime 的值从小时转换为天?
- java - rxjava 转换操作(平面图使用)
- c - 使线程休眠一段时间或直到唤醒的便携式方法
- javascript - 将属性对象(使用 this.id 的 onclick 函数)传递给 HTML 元素构造函数
- javascript - 如何使用 HTML (JavaScript) 代码将常规文本变量转换为变量?
- javascript - 在反应js中动态上传图像
- apache-spark - 如何在 Pyspark IDE(Pycharm/Eclipse)中配置外部 JAR
- database - 对于大于 28 G 的大表,SQLite3 读写速度极慢