react-native 把图片转化base64字符串

1).导入’react-native-fs’

import RNFS from 'react-native-fs';

2).通过react-native-fs包中的readFile()获取base64数据


 _convertImageToBase64(img) {
        if (!img) {
            return;
        }

        RNFS.readFile(img.path, 'base64')
            .then((content) => {
                // content 为base64数据
                console.log("content",content)

            })
            .catch((err) => {
                console.log("reading error: " + err);
            });


    }

你可能感兴趣的:(react-native)