我正在尝试将资产从一个环境迁移到同一空间中的另一个环境。
我正在使用createAssetWithId
中的Contentful Management API
方法将资产及其ID从source
环境迁移到target
环境。
但是,发布时出现此错误:
ValidationFailed: {
"status": 422,
"statusText": "Unprocessable Entity",
"message": "Validation error",
"details": {
"errors": [
{
"name": "badFileUrl",
"path": [
"fields",
"file",
"en-US",
"url"
],
"details": "Invalid asset URL"
}
]
},
"request": {
"url": "assets/5KRzAvo7a4xq7iuLuuQ9B3/published",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/vnd.contentful.management.v1+json",
"X-Contentful-User-Agent": "sdk contentful-management.js/5.28.0; platform node.js/v10.16.2; os Windows/10.0.18362;",
"Authorization": "Bearer ...fbbFQ",
"user-agent": "node.js/v10.16.2",
"Accept-Encoding": "gzip",
"X-Contentful-Version": 2
},
"method": "put",
"payloadData": null
},
"requestId": "f77f2c74115b8bf071fd58455f26bd27"
}
这是creating
和processing
资产的代码。之后是发布部分。
await cmaClient.getSpace(spaceId)
.then(async (space) => await space.getEnvironment(environmentId))
.then(async (environment) => await environment.createAssetWithId(assetItem.sys.id, { fields: assetItem.fields }))
.then(async (asset) => await asset.processForAllLocales({ processingCheckWait: 5000, processingCheckRetries: 25 }))
.then(customLogger.success(`Asset '${assetItem.sys.id}' has been created.`))
.catch(customLogger.error)
assetItem.fields
具有以下属性:
{ title: { 'en-US': 'image title' },
description: { 'en-US': ' ' },
file:
{ 'en-US':
{ fileName: '',
contentType: 'image/jpeg',
upload:
'https://images.ctfassets.net/<space_id>/<asset_id>/2hj84bce4dedcfc78654b98hhhr452t7/image.jpg' } } }
资产已创建,但图像未显示,未处理且因此未发布。