Taro React component development (10) —— RuiUploadImages multi-image upload component [transfer to base64]

1. Demand Analysis

  1. Use Taro.chooseImage to realize the selection of pictures;
  2. Use Taro.request to upload pictures;
  3. The WeChat applet uses the readFile of Taro.getFileSystemManager to realize the base64 conversion of local pictures;
  4. 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 =>

Guess you like

Origin blog.csdn.net/m0_38082783/article/details/131491701