React Native save base64 image to Album

前端 未结 5 1774
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 21:22

Third Party API return a \"QR code image\" in base64 encode,
I need save that image to User\'s Album.

  • CamerRoll - not support saving base64 image to album <
5条回答
  •  名媛妹妹
    2021-02-05 21:37

    I got this worked in following example

    import RNFetchBlob from 'rn-fetch-blob';
    import Permissions from 'react-native-permissions';
    
     takeSnapshot = async () => {
        const currentStatus = await Permissions.check('storage');
    
        if (currentStatus !== 'authorized') {
          const status = await Permissions.request('storage');
    
          if (status !== 'authorized') {
            return false;
          }
        }
    
        // put here your base64
        const base64 = '';
    
        const path = `${RNFetchBlob.fs.dirs.DCIMDir}/test11.png`;
    
        try {
          const data = await RNFetchBlob.fs.writeFile(path, base64, 'base64');
          console.log(data, 'data');
        } catch (error) {
          console.log(error.message);
        }
      };
    

提交回复
热议问题