提供为什么不建议在CoreData中存储图像的示例? [英] Provide example for why it is not advisable to store images in CoreData?

查看:110
本文介绍了提供为什么不建议在CoreData中存储图像的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已被问过很多次,我已经读过许多用户告诉我们不建议在DB中存储图像,特别是在CoreData中。他们似乎都忽略了他们为什么会这样做的原因。甚至苹果的文档都说明了这一点,每个人都指向这个方向,每个讨论都会这样结束,你可以,但存储路径更好。



,我想有一个具体的例子,为什么它不是一个很好的解决方案。



我更好地解释,我有一个强大的背景构建Web应用程序。从我的观点来看,一个具体的例子可能是:不要将图像存储在DB中,而是存储到它们的路径,因为您可以通过Web服务器为它们提供服务,这可以应用所有的缓存问题。



但在桌面环境中,尤其是在iOS应用程序中,使用sqllite存储在Core Data中的缺点是:


有一个单独的实体保存图片,它不是主实体的属性


似乎图片的上限为100kb。为什么?

$

解决方案

Core Data通常在这里没有什么特别之处。它只是使用 SQLite 数据库。你可以把大量的数据放入它,但它只是不能缩放所有这一切。您可以在这里阅读更多内容:内部与SQLite中的外部BLOB

这说明,Core Data支持外部blob ,在Core Data术语中称为存储在外部记录 (iOS 5.0及更高版本)。再次,没有什么奇怪的,它只是存储大型数据在文件系统中独立于SQLite数据库本身。



当你在Xcode中时,会有一个复选框,名为允许外部存储您可以检查二进制数据属性。


this question has been asked many times, I have read many users telling that it is not advisable to store images in a DB, in particular within CoreData. By they all seems to omit the reason why they would do so. Even Apple documentation state this, and everybody points to that direction, and every discussion end like this "well you can, but storing the path is better".

Apart from opinions, I would like to have a concrete example of why it is not a good solution.

I explain better, I have a strong background in building Web Application. A concrete example I would give from my point of view could be: do not store images in a DB, but rather the path to them, because you can have them served them by the web server, which can apply all of its caching issues.

But in a desktop environment, especially in iOS application, what are the downside of having stored in Core Data using sqllite, providing that:

There's a separate entity holding the images, it is not an attribute of main entity

Also seems to be a limit of 100kb for images. Why ? What does happen with a 110,120...200kb ecc ?

thanks

解决方案

There's nothing special about what Core Data normally does here. It's just using an SQLite database. You can put large blobs of data into it, but it just doesn't scale all that well. You can read more about it here: Internal Versus External BLOBs in SQLite.

That said, Core Data has support for external blobs which in Core Data terminology is called stored in external record (iOS 5.0 and later). Again, there's nothing magic about it, it's just storing the large pieces of data in the file system separately from the SQLite db itself. The benefit is that Core Data updates all this for you.

When you're in Xcode, there'll be a checkbox called Allows External Storage that you can check for Binary Data properties.

这篇关于提供为什么不建议在CoreData中存储图像的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆