React-Native: Convert image url to base64 string

前端 未结 9 558
轻奢々
轻奢々 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:38

    The standalone expo FileSystem package makes this simple:

    const base64 = await FileSystem.readAsStringAsync(photo.uri, { encoding: 'base64' });
    
    • https://docs.expo.io/versions/latest/sdk/filesystem/
    • https://github.com/expo/expo/tree/master/packages/expo-file-system

    As 2019-09-27 this package handles both file:// and content:// uri's

提交回复
热议问题