1. Demand Analysis
- Use Taro.chooseImage to realize the selection of pictures;
- Use Taro.request to upload pictures;
- The WeChat applet uses the readFile of Taro.getFileSystemManager to realize the base64 conversion of local pictures;
- H5 uses fetch and FileReader to convert base64 of local images.
2. Wechat applet implements base64 conversion
import { getFileSystemManager } from '@tarojs/taro';
// 微信小程序端获取图片的base64
function getWeappBase64 (filePath) {
return new Promise((resolve, reject)=>{
let fileManage = getFileSystemManager();
fileManage.readFile({
filePath,
encoding:'base64',
success:(e)=>{
resolve(`data:image/jpg;base64,${e.data}`)
},
fail: err =>