React-Native: Convert image url to base64 string

前端 未结 9 555
轻奢々
轻奢々 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);
            });
    

提交回复
热议问题