gpt4 book ai didi

ios - 如何在 CloudKit 中存储大图像?

转载 作者:可可西里 更新时间:2023-11-01 04:25:06 25 4
gpt4 key购买 nike

我尝试将图片上传到 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)")
  • d.length: 55482 <- 有效
  • d.length: 17614327 <- 不起作用

最佳答案

您应该将图片存储为 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")!))

关于ios - 如何在 CloudKit 中存储大图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27817690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com