如何在CloudKit中存储大图像? [英] How to store big image in CloudKit?

查看:459
本文介绍了如何在CloudKit中存储大图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将图片上传到 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 <- works
    • d.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对象执行此操作。
      记录数据的总大小限制为1 MB,但资产不计入

      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:

      You can create a CKAsset like this:

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

      这篇关于如何在CloudKit中存储大图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆