Getting record undefined error when using node and cloudkit js to save image file to a record

Getting record undefined error when using node js and cloudkit js to save image file to a record.

The image is stored in a field called 'data' with field type 'Bytes'.


fs.readdirSync(readImageFolder).forEach(file => {

var imageData = fs.readFileSync(readImageFolder + '//' + file);

filename = file.slice(0, -4);

newRecord = {

recordName: filename,

recordType: 'Images',

fields: { data: {value: imageData} }

};

})


After calling database.saveRecords(newRecord), the response came back with record undefined and the record was not saved


CloudKitJS RecordsBatchBuilder#commit

--> Saved Record:

undefined


Maybe I have to convert the imageData to a different data type before calling saveRecords?


Thanks!

Replies

Have you verified that you can save a record with that field removed and then, immediately when you add that field, you can no longer save the record? (FYI - as of a few hours ago either I screwed up something or CloudKit is not working - I can save nothing. Most likely I screwed up somethng but check to be sure.)

Yes, I can save the record successfully without the image field. Thanks.

I have now succeeded and maybe my error is related. I was trying to save fields that were not included in the previous deploy-development-to-production and that caused everything to work except for the save.

Sorry, I'm new to the technology. Will you please elaborate on how you were able to save record with Bytes field? Thank you!

I am not sure what your question is. According to:

https://developer.apple.com/documentation/cloudkit/ckrecord?language=objc

a CKRecord can have an NSData object as a value in a field.'