简体   繁体   中英

Handling images in react-native realm

I have a list of products with each product having an imageURL field that points to a remote image. The products are persisted with realm. The challenge now is downloading the images and making them available offline.

How do I fetch images from remote URL and persist using realm?

Realm React Native features a data property type, so you could save the image data directly to Realm if you wanted.

However, for large binary files that won't change often, we usually recommend you store the image files on disk, outside of Realm, and then simply have a string property in Realm referencing the name/path of that file.

After doing a quick search on GitHub, there appears to be a React Native plugin that can manage downloading and storing files on disk.

My recommendation is that you use that library (or a similar one if you want) to download the image file to disk, and then store a reference to its file name in Realm, so you know which image file matches the Realm object. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM