简体   繁体   English

处理反应原生境中的图像

[英]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. 我有一个产品列表,每个产品都有一个指向远程图像的imageURL字段。 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? 如何从远程URL获取图像并使用域继续?

Realm React Native features a data property type, so you could save the image data directly to Realm if you wanted. Realm React Native具有data属性类型,因此您可以根据需要将图像数据直接保存到Realm。

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. 但是,对于不会经常更改的大型二进制文件,我们通常建议您将图像文件存储在Realm之外的磁盘上,然后在Realm中简单地引用一个字符串属性,引用该文件的名称/路径。

After doing a quick search on GitHub, there appears to be a React Native plugin that can manage downloading and storing files on disk. 在GitHub上快速搜索之后,似乎有一个React Native插件可以管理在磁盘上下载和存储文件。

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. 我的建议是您使用该库(或类似的库)将图像文件下载到磁盘,然后在Realm中存储对其文件名的引用,以便您知道哪个图像文件与Realm对象匹配。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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