Search code examples
imagefilereact-nativestoragerealm

React-Native / Realm : how to store an image in the database?


My app has to regularly download some content and keep it available offline. I use Realm for that and so far the experience has been great. But I really don't know what to do when it comes to images. I could store a ref to the paths but I'd really prefer Realm's direct storage. Is there a not-too-complex way to achieve that ?

N.B In fact I'd be looking for a snippet like the one above, which would perfectly fill my needs... but this is for IOS, not react-native -> How to put an image in a Realm database?


Solution

  • I can't seem to find a built it React Native api for dealing with images already stored in memory, and without this it may not make sense to store images in Realm.

    It does look like React Native can open images from the filesystem though with paths specified at runtime - https://facebook.github.io/react-native/docs/images.html#network-images

    If you take this route you can download/save the image to disk, and simply save the path to the image in Realm.