uni-app上传头像base64转码

uni-app上传头像base64转码

首先需要调起相册,使用 uni.chooseImage 方法选择相册,点击相册里面的图片,
确定可以选择图片并获取到图片的路径之后,uni-app官网有插件可以来使用,引入插件之后,使用插件的方法就可以获取base64转码。
插件网址:http://ext.dcloud.net.cn/plugin?id=123

import { pathToBase64, base64ToPath } from '../../../common/image-tools.js'
 uni.chooseImage({
	 sourceType: ["camera", "album"],
	 sizeType: "compressed",
	 count: 1,
	 success: (res) => {
		 pathToBase64(res.tempFilePaths[0])
			.then(base64 => {
				console.log(base64);
			 })
			 .catch(error => {
				console.error(error);
			 });
  		}
    });


 

发布了110 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Lemontree_fu/article/details/103823859