mmm*_*che 0 contentful contentful-management
我一直在使用Contentful Management Javascript SDK更新Contentful空间中的条目,并且能够使用文本更新简单字段没有问题.
我的问题是我无法弄清楚如何在我的条目中更新图像 ; 我可以将图像上传到媒体部分,但我无法将任何图像分配给入口属性.
这是可能的还是Contentful的限制?
到目前为止,这是我的代码:
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;
});
});
});
Run Code Online (Sandbox Code Playgroud)
嗨,我是js SDK的维护者,这里假设你有一个名为imagemedia media 的字段,你可以在你的条目中添加一个资产.
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
entry.fields["image"]["en-GB"] = {"sys": {"id": asset.sys.id, "linkType": "Asset", "type": "Link"}};
return entry.update()
});
});
});
Run Code Online (Sandbox Code Playgroud)