问题描述
我尝试将图片上传到 CloudKit
,并将其存储为 NSData
,但图片相对较大,用相机拍摄,我收到此错误:
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
什么数据的最大大小是否可以存储在 CloudKit
?
What is the maximum size of data is able to store in CloudKit
?
如何存储用相机拍摄的大图像在 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
< - 作品 -
d.length:17614327
< - 不起作用 d.length: 55482
<- worksd.length: 17614327
<- does not work
推荐答案
您应该将图片存储为CKAsset。对于CKRecord,存在尺寸限制。对于CKAsset,没有(除了CloudKit存储限制)。根据文档:
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:
你可以像这样创建一个CKAsset:
You can create a CKAsset like this:
var File : CKAsset = CKAsset(fileURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("image-not-available", ofType: "jpg")!))
这篇关于如何在CloudKit中存储大图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!