I have been using the Contentful Management Javascript SDK to update entries in my Contentful space and have been able to update simple fields with text no problem.
My issue is that I can't figure out how to update images in my entry; I can upload images to the media section okay, but I haven't been able to assign any images to an entry property.
Is this possible or is this a limitation of Contentful?
Here's my code so far:
client.getSpace(CONTENTFUL_SPACE).then((space) => {
// retrieve my Contentful space
space.getEntry(CONTENTFUL_ENTRY).then(function (entry) {
// get a specific entry
// create a new asset in my Contentful media section
space.createAssetWithId(RANDOM_ID, {
fields: {
file: {
'en-GB': {
contentType: 'image/jpeg',
fileName: 'test.jpg',
upload: 'http://www.example.com/test.jpg'
}
}
}
})
.then(asset => asset.processForAllLocales())
.then(asset => asset.publish())
.then(function(asset) {
// assign uploaded image as an entry field
// (none of these work:)
entry.fields["image"]["en-GB"] = asset.sys.id;
entry.fields["image"]["en-GB"] = asset.fields.file["en-GB"].url;
entry.fields["image"]["en-GB"] = asset;
});
});
});