创建新条目时添加媒体字段
Adding a media field when creating a new entry
我四处搜索并查看了所有 SDK 文档和 Contentful 的 API 文档 我很难理解如何在创建资产时将带有 link 的媒体字段添加到资产新条目。我可以成功创建其他字段,但媒体字段应该是一个对象,但我不确定如何设置格式以便 Contentful 接受它。
const videoAsset = yield client.getAsset(assetID)
fields = {
title: {
"en-US": 'Title' //works
},
description: {
"en-US": 'Description' //works
},
video: {
"en-US": //contenful api wants an object, what does this object look like?
//i have a published asset in videoAsset returned by client.getAsset()
},
team: {
"en-US": 'Community' //works
},
}
const entryCreated = yield space.createEntry(action.payload.contentType, {
fields: fields
})
当我说 "works" 时,我的意思是我可以成功创建一个出现在 Contentful space 中的条目。
我明白了!
此人并没有做完全相同的事情,但格式方面的答案在这里:
https://github.com/contentful/contentful-management.js/issues/57
基本上该字段应如下所示:
const videoAsset = yield client.getAsset(assetID)
fields = {
title: {
"en-US": 'Title' //works
},
description: {
"en-US": 'Description' //works
},
video: {
"en-US": {
sys: {
type: "Link", linkType: "Asset", id: assetID
}
}
}, //this formatting works!
team: {
"en-US": 'Community' //works
},
}
const entryCreated = yield space.createEntry(action.payload.contentType, {
fields: fields
})
我四处搜索并查看了所有 SDK 文档和 Contentful 的 API 文档 我很难理解如何在创建资产时将带有 link 的媒体字段添加到资产新条目。我可以成功创建其他字段,但媒体字段应该是一个对象,但我不确定如何设置格式以便 Contentful 接受它。
const videoAsset = yield client.getAsset(assetID)
fields = {
title: {
"en-US": 'Title' //works
},
description: {
"en-US": 'Description' //works
},
video: {
"en-US": //contenful api wants an object, what does this object look like?
//i have a published asset in videoAsset returned by client.getAsset()
},
team: {
"en-US": 'Community' //works
},
}
const entryCreated = yield space.createEntry(action.payload.contentType, {
fields: fields
})
当我说 "works" 时,我的意思是我可以成功创建一个出现在 Contentful space 中的条目。
我明白了!
此人并没有做完全相同的事情,但格式方面的答案在这里:
https://github.com/contentful/contentful-management.js/issues/57
基本上该字段应如下所示:
const videoAsset = yield client.getAsset(assetID)
fields = {
title: {
"en-US": 'Title' //works
},
description: {
"en-US": 'Description' //works
},
video: {
"en-US": {
sys: {
type: "Link", linkType: "Asset", id: assetID
}
}
}, //this formatting works!
team: {
"en-US": 'Community' //works
},
}
const entryCreated = yield space.createEntry(action.payload.contentType, {
fields: fields
})