如何在 React "Failed to load resource: the server responded with a status of 404 ()" 中显示上传到 Cloudinary



按照此处的指示https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_resources

我使用fetch API访问.json文件来显示上传的媒体,但出现错误";加载资源失败:服务器的响应状态为404((";

这是我的代码

useEffect(() => {
fetch(window.cloudinary.url("reactflix.json", {type: "list"}))
.then(res => res.json())
.then(
(result) => {
console.log(result)
},

(error) => {
console.log('error')
}
)
}, []);

我也试过

useEffect(() => {
fetch('https://res.cloudinary.com/omama/image/list/reactflix.json')
.then(res => res.json())
.then(
(result) => {
console.log(result)
},

(error) => {
console.log('error')
}
)
}, []);

客户端资源(又名资源列表(在默认情况下受到限制,并且需要签名URL才能访问。由于您没有使用签名URL,404最可能的原因是您帐户内的设置是默认设置,因此此类型受到限制。

您可以通过转到"设置"->安全标签在您的帐户和字段下";受限媒体类型";确保";资源列表";选项未选中。如果是,则可以取消选中并保存设置。

完成后,您可以使用以前没有测试过的新标签进行测试。这是因为,如果404的原因确实是限制,那么您可能会从Cloudinary获得缓存的错误响应。使用新标签进行测试可以确保您不会遇到这种情况。

您在哪里找到云名称"omama";并且标签";reactflix.json";?你可能想检查一下。

大多数情况下,客户端请求只是简单的URL,所以你不需要检查你的应用程序,你可以在浏览器中访问它,但我建议使用Postman。如果URL在您的浏览器中没有返回任何内容,则将被视为404。

相关内容

最新更新