5

I tried to upload a picture to CloudKit, and store it as NSData, but with a relatively bigger picture, taken with camera, I get this error:

Error saving record <CKRecordID: 0x15998770; 04359DFA-8370-4000-9F53-5694FC53FA9C:(_defaultZone:__defaultOwner__)> to server: record too large id=04359DFA-8370-4000-9F53-5694FC53FA9C of type UserSetting

What is the maximum size of data is able to store in CloudKit?

How do you store big images taken with camera in CloudKit?

I tried with two image, and I plotting out size of them.

let d = UIImagePNGRepresentation(image)
println("d.length: \(d.length)")
  • d.length: 55482 <- works
  • d.length: 17614327 <- does not work
János
  • 32,867
  • 38
  • 193
  • 353

1 Answers1

9

You should store pictures as a CKAsset. For a CKRecord there is a size limitation. For a CKAsset there is not (beside the CloudKit storage limitations). According to the documentation:

Use assets for discrete data files. When you want to associate images or other discrete files with a record, use a CKAsset object to do so. The total size of a record’s data is limited to 1 MB though assets do not count against that limit.

You can create a CKAsset like this:

var File : CKAsset = CKAsset(fileURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("image-not-available", ofType: "jpg")!))
Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • 5
    From [Apple](https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKAsset_class/index.html) : *The files or data you save using an asset object must be no larger than 250 MB.* – Mojo66 Aug 26 '15 at 22:36
  • Is there any way to create a URL from an image? I have the user choose between clicking the image within the app or using a UIImagePickerController. – Pranav Wadhwa Nov 08 '16 at 14:58
  • Edwin, If you can look at [this](https://stackoverflow.com/questions/61186769/records-zone-doesnt-displayed-in-dashboard-and-delete-zone-issue-cloudkit) and help me, please – Bhavin Bhadani Apr 13 '20 at 11:30