Imgix清除请求失败原因未知。

3
我想从imgix缓存中清除一张图片,他们提供了相关的API(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标头,就像在他们的示例中一样,但那也没有起作用。

由于我无法从响应中获取更多信息,因此在这里请求帮助,因为我不知道该如何继续。

1个回答

4

查看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" } }'

因此,只需修改您的消息(向您的JSON对象添加数据属性):
const data = JSON.stringify({
  data: {
        type: 'purges',
        attributes: {
            url: href,
            source_id: 'SOsourceId',
        },
    }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接