I want to save a CK record with a png-image as data into an asset field. The image is representated by a base64-string variable in the javascript. Have given up after one week searching for an answer.
As documented here, you need to pass a Blob
to saveRecords
method. Assuming the base64
string has the content type you can achieve this like:
fetch(base64String)
.then((response) => response.blob())
.then((blob) =>
database.saveRecords({
recordType: RECORD_TYPE_NAME,
fields: {
[ASSET_FIELD_NAME]: { value: blob },
},
})
);
If the base64 is missing the content type, you can prepend it like data:image/png;base64,${base64String}
;