Images storage performance react native (base64 vs uri path)

I try to avoid text only answers; including code is best practice but the question about storing images comes up frequently and it’s not really covered in the documentation so I thought it should be addressed at a high level.

Generally speaking, Realm is not a solution for storing blob type data – images, pdf’s etc. There are a number of technical reasons for that but most importantly, an image can go well beyond the capacity of a Realm field. Additionally it can significantly impact performance (especially in a sync’ing use case)

If this is a local only app, storing the images on disk in the device and keep a reference to where they are (their path) stored in Realm. That will enable the app to be fast and responsive with a minimal footprint.

If this is a sync’d solution where you want to share images across devices or with other users, there are several cloud based solutions to accommodate image storage and then store a URL to the image in Realm.

One option is part of the MongoDB family of products (which also includes MongoDB Realm) called GridFS. Another option is a solid product we’ve leveraged for years is called Firebase Cloud Storage.

Now that I’ve made those statements, I’ll backtrack just a bit and refer you to this article Realm Data and Partitioning Strategy Behind the WildAid O-FISH Mobile Apps which is a fantastic article about implementing Realm in a real-world use application and in particular how to deal with images.

In that article, note they do store the images in Realm for a short time. However, one thing they left out of that (which was revealed in a forum post) is that the images are compressed to ensure they don’t go above the Realm field size limit.

I am not totally on board with general use of that technique but it works for that specific use case.

One more note: the image sizes mentioned in the question are pretty small (500 ~~ 800 kb img size) and that’s a tiny amount of data which would really not have an impact, so storing them in realm as a data object would work fine. The caveat to that is future expansion; if you decide to later store larger images, it would require a complete re-write of the code; so why not plan for that up front.

Leave a Comment