简体   繁体   English

Strapi v4 REST API:获取图像 [关闭]

[英]Strapi v4 REST API :GET image [closed]

please I am working with the new strapi v4 and... In the old versions of strapi all I needed to do in order to get the image from my collection type was to get it like: <img src={config.baseURL + product?.productImg?.formats?.thumbnail?.url} /> but when I try to do the same now, it gives me the url address, but the response says我正在使用新的 strapi v4 和...在旧版本的 strapi 中,为了从我的收藏类型中获取图像,我需要做的就是像这样获取它: <img src={config.baseURL + product?.productImg?.formats?.thumbnail?.url} />但当我现在尝试做同样的事情时,它给了我 url 地址,但回复说

{"data":null,"error":{"status":404,"name":"NotFoundError","message":"Not Found","details":{}}}

Any help?有什么帮助吗?

with strapi v4 u need to manually populate your rest api with images otherwise it's restricted due to security reasons:使用 strapi v4,你需要手动填充你的 rest api 图片,否则由于安全原因它会受到限制:

localhost:1337/api/posts?populate=*

then you will get images on your endpoint然后您将在端点上获得图像

I realised it.我意识到了。 In my config file I had the baseURL as 'localhost:1337/api'.在我的配置文件中,我的 baseURL 为 'localhost:1337/api'。 However for images, you must request without the '/api' so the request should be just 'localhost:1337' and then the image route.但是对于图像,您必须在没有“/api”的情况下进行请求,因此请求应该只是“localhost:1337”,然后是图像路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM