React-Native: Convert image url to base64 string

前端 未结 9 515
轻奢々
轻奢々 2020-12-08 19:03

I\'m building a react native app that needs to store images at base64 string format for offline viewing capabilities.

What library / function would give me the best

相关标签:
9条回答
  • 2020-12-08 19:53

    For me upalod file mp4 from local file on devies to Facebook or another social:

    var data = await RNFS.readFile( `file://${this.data.path}`, 'base64').then(res => { return res });
            const shareOptions = {
                title: 'iVideo',
                message: 'Share video',
                url:'data:video/mp4;base64,'+ data,
                social: Share.Social.FACEBOOK,
                filename: this.data.name , // only for base64 file in Android 
            };     
            Share.open(shareOptions).then(res=>{
               Alert.alert('Share Success`enter code here`!')
            }).catch(err=>{
                console.log('err share', err);
            });
    
    0 讨论(0)
  • 2020-12-08 19:59
     ImageEditor.cropImage(imageUrl, imageSize, (imageURI) => {
          ImageStore.getBase64ForTag(imageURI, (base64Data) => {
              // base64Data contains the base64string of the image
          }, (reason) => console.error(reason));
     }, (reason) => console.error(reason));
    
    0 讨论(0)
  • 2020-12-08 20:00

    react-native-image-picker includes a base64 data node in the returned object. fyi

    0 讨论(0)
提交回复
热议问题