javascript - 如何在本机反应中制作javascript图像blob对象?
问题描述
我必须像这样制作一个图像 blob 对象:
现在我可以在我存储在变量中的 react native 中获取图像 base64 url:
const base64 = img.data;
我试过这种方式但没有奏效:
function b64toBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], {type: 'image/jpeg'});
}
const blob = b64toBlob(base64);
console.log(blob);
const base64 = img.data;
现在,如何在 react native 中使用这个 base64 变量创建一个像上图一样的 blob 对象?
解决方案
我这样解决了这个问题:
ImagePicker.openPicker({
width: 400,
height: 400,
cropping: true,
includeBase64: true,
})
.then(image => {
setImg(image);
})
.then(() => setModalVisible(prev => !prev));
const image = {
name: nn,
uri: img.path,
type: img.mime,
size: img.size,
lastModifiedDate: JSON.parse(img.modificationDate),
uid: img.modificationDate,
};
const form = new FormData();
form.append('file', image);
axios
.post('url', form, {
headers: {
Authorization: `bearer ${JSON.parse(token)}`,
},
})
推荐阅读
- c++ - “充分表达”与“充分表达”
- sql - 如何确定数据集中的开始和结束活动?
- php - 如果未登录,则重定向到 login.php
- python - Django 管理员批量删除排除某些查询集
- javascript - VueJS - 使用 sortableJS 时检测 VueJS 范围内的 DOM 变化
- c - 这段代码计算不正确,有什么想法吗?
- ios - Crashed: com.apple.main-thread EXC_BREAKPOINT 0x0000000100c5009c keyboard_arrow_up
- javascript - 反应JS | 根据标志显示或隐藏对象数组
- python - Python 3.6.1 模块_mssql 找不到libsybdb-89a09a88.so.5.1.0
- java - 如何测试服务层,在springMVC和java7级别语言中使用@Autowired。UnsupportedClassVersionError 问题