我想从imgix缓存中清除一个图像,他们有一个应用程序接口(https://docs.imgix.com/setup/purging-images)
我使用axios从我的nodejs后端发出请求:
const imgixKey = functions.config().imgix.key;
const headers = {
Authorization: `Bearer ${imgixKey}`,
'Content-Type': 'application/json',
};
const data = JSON.stringify({
type: 'purges',
attributes: {
url: href,
source_id: 'SOsourceId',
},
});
try {
await axios.post('https://api.imgix.com/api/v1/purge', data, { headers });
functions.logger.log('Purged Image successfully' + href);
} catch (e) {
functions.logger.error('Error removing image from cache ' + href + ' -> ' + e);
}Error removing image from cache {stackoverflowimgpath.png} -> Error: Request failed with status code 400 问题是,除了状态码400之外,没有指定任何其他内容,我检查了图像路径,并尝试了不同的Content-Type头文件,就像他们的示例中一样,但也不起作用。
由于我无法从响应中获得更多信息,因此我在此请求帮助,因为我不知道如何继续。
发布于 2021-06-16 21:50:02
检查imgix文档,请求的正文应该有一个数据属性:
curl -X POST 'https://api.imgix.com/api/v1/purge' \
--header 'Authorization: Bearer <api-key>' \
--header 'Content-Type: application/vnd.api+json' \
--data-raw '{ "data": { "attributes": { "url": "<url-to-purge>" }, "type": "purges" } }'因此,只需将消息修改为(将data属性添加到json对象):
const data = JSON.stringify({
data: {
type: 'purges',
attributes: {
url: href,
source_id: 'SOsourceId',
},
}
});https://stackoverflow.com/questions/68003875
复制相似问题