What is CloudKit error: AssetUploadTokenRetrieveRequest request size exceeds limit

Some of my customer get the following CloudKit error (I cannot reproduce is myself).

Failed to modify some records (CKErrorDomain:2) 
userInfo: CKErrorDescription:Failed to modify some records CKPartialErrors:{ 
"<CKRecordID: ooo; recordName=ooo, zoneID=ooo:__defaultOwner__>" 
= "<CKError 0x600003809ce0: \"Limit Exceeded\" (27/2023); server message = \"AssetUploadTokenRetrieveRequest request size exceeds limit\"; 
  op = ooo; uuid = ooo; container ID = \"ooo\">"

This is a CKError.limitExeeded error. I create 200 or less records in a batch operation. So I am below the 400 limit.

Searching the Internet for "AssetUploadTokenRetrieveRequest request size exceeds limit": 0 results

Can anyone give me a hint?

Answered by DTS Engineer in 825340022

I believe that you need one token per asset field. If your request tend to upload 100 records and each record has one asset field, you will need 100 tokens.

I haven't really hit the limit with my code though, and so will be curious if you see anything beyond the rule.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

When you save CloudKit records, the client needs to request a token for each asset field, if any, for uploading the asset data, and the maximum number of tokens in a request is limited to 200, as mentioned in Data Size Limits.

Since you "create 200 or less records in a batch operation," I'd guess that it is the token number hitting the limit. If that is the case, having your operations handle smaller batches should avoid hitting the limit.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank for your quick reply.

Ok understood. So there are two possible solutions.

  1. Quick and dirty: Reduce the batch size to 100
  2. Reliable: Split the batch size and retry recursively until no limit exceeded error is returned.

BUT

"and the maximum number of tokens in a request is limited to 200" How can I predict how many tokens are needed for my request? Is there any documentation available?

Accepted Answer

I believe that you need one token per asset field. If your request tend to upload 100 records and each record has one asset field, you will need 100 tokens.

I haven't really hit the limit with my code though, and so will be curious if you see anything beyond the rule.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thank you for your reply. I will update the app now and send it out and we will see how step 1 works.

What is CloudKit error: AssetUploadTokenRetrieveRequest request size exceeds limit
 
 
Q