0

I would like to load images from disk and add them to core data. I have an attribute set as transformable.

I would like to get directions on how I should read the images and then add them to the entity. Later I would like to show the image in an image well using bindings.

Should I read the files as NSData?

Sidenote,

I also have the base64 data for the images in a JSON. Is it better to read and add the base64 to core data? When I tested reading and adding the base64 code I got the impression that it's a slow

Mikael
  • 3,572
  • 1
  • 30
  • 43

1 Answers1

0

The recommended way to do this is to store the images in the file system and just store the file name / parts of the path in Core Data.

The reason is that big BLOBs (the internal SQLite format) can slow down your database significantly. Only relatively small images (such as thumbnails) can be handled by Core Data reasonably.

Your experience about Core Data being "slow" is exactly due to this phenomenon. It follows that your images are not small enough to be stored in core data. Therefore, you do not need to bother with transforming Core Data stored images into UIImage. Your approach with NSDatais correct.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks for your answer! Let's say I store the path to the files in Core Data, how would one use this in the bindings with the Image Well? About BLOBs, wouldn't 'Store in External Record File' solve that? – Mikael Jan 20 '13 at 14:52
  • Storing images externally would of course obliterate the need to store BLOBs in Core Data. I just mentioned it as an explanation. The proposed setup is quite independent from how you present the data, including Image Well. – Mundi Jan 20 '13 at 20:21
  • What I did was adding the path to the image file in to Core Data, just as you said. Then I used "Value Path" for the bindings. Thanks! – Mikael Jan 20 '13 at 20:21