如何在 CloudKit 中存储大图像?

How to store big image in CloudKit?

我尝试将图片上传到 CloudKit,并将其存储为 NSData,但是使用相机拍摄的相对较大的图片出现此错误:

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

CloudKit 中能够存储的最大数据量是多少?

如何在 CloudKit 中存储用相机拍摄的大图像?

我尝试了两张图片,并标出了它们的大小。

let d = UIImagePNGRepresentation(image)
println("d.length: \(d.length)")

您应该将图片存储为 CKAsset。对于 CKRecord 有大小限制。对于 CKAsset 没有(除了 CloudKit 存储限制)。根据文档:

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.

您可以像这样创建一个 CKAsset:

var File : CKAsset = CKAsset(fileURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("image-not-available", ofType: "jpg")!))