【发布时间】:2021-10-28 16:41:57
【问题描述】:
我需要将来自图像选择器的文件 Uri 响应转换为 base64 字符串。
我已经尝试使用文件阅读器将文件 uri 转换为 base64,但它不起作用。
const options: ImagePickerOptions = {
maximumImagesCount: 1,
width: 1200,
height: 1200,
quality: 80
};
this.imagePicker.getPictures(options).then(async (results) => {
const fileData: string = results[0];
const path: string = fileData.substring(0, fileData.lastIndexOf('/') + 1);
const fileName: string = fileData.split('/').pop();
console.log(fileName, "fileName");
console.log(path, "Path");
this.file.readAsDataURL(path, fileName)
.then((base64File) => {
console.log("here is encoded image ", base64File)
})
.catch((err) => {
console.log('Error reading file', err);
})
});
请让我知道我哪里出错了。感谢任何建议或解决方案。 提前致谢。
【问题讨论】:
标签: angular image ionic-framework base64