【问题标题】:Adding a media field when creating a new entry创建新条目时添加媒体字段
【发布时间】:2018-01-13 17:22:20
【问题描述】:

我四处搜索并查看了所有 SDK 文档和 Contentful 的 API 文档,我很难理解如何在创建新条目时添加带有资产链接的媒体字段。我可以成功创建其他字段,但媒体字段应该是一个对象,但我不确定如何格式化,以便 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
})

当我说“有效”时,我的意思是我可以成功创建一个出现在内容空间中的条目。

【问题讨论】:

    标签: contentful-management


    【解决方案1】:

    我明白了!

    这个人所做的事情并不完全相同,但格式方面的答案就在这里:

    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
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 2020-07-01
      • 2018-01-16
      • 2014-11-06
      • 1970-01-01
      • 2022-11-29
      • 2020-05-04
      • 2018-12-17
      相关资源
      最近更新 更多