Ajay Singh Beniwal
Ajay Singh Beniwal

Reputation: 19037

Store remote 2d barcode in React Native

I am developing a prototype for a mobile ticketing platform where I have to create 2D barcode ticket for the user , currently I am creating 2D barcode from google chart service and displaying it using Image Tag.But Now I do not want to hit remote source every time , I want to download image on first time and save it on local phone source . So I need guidance to where should I store this image in Async Storage or CameraRoll

Thanks

Upvotes: 2

Views: 250

Answers (1)

Colin Ramsay
Colin Ramsay

Reputation: 16477

If you store your images in Camera Roll then they'll be visible to the phone's user when they browse their photos and they could potentially get synced to iCloud. This seems to me to be bad form.

AsyncStorage is a key-value storage mechanism, and the value is expected to be a string. You could use this if you base64 encoded your images, but you'd also have to store another value to track a list of the images you were keeping in AsyncStorage.

I don't think either of these are ideal. Personally I'd look into storing them on the device's filesystem, and fortunately there's a project that seems to enable you to do just that: react-native-fs "Native filesystem access for react-native". I think this is the most natural approach and will allow you to iterate over your stored images.

A final idea is to use a database; you could perhaps use one of these:

https://github.com/mafintosh/browserify-fs (uses level.js behind the scenes) https://github.com/almost/react-native-sqlite (sqlite)

Upvotes: 1

Related Questions