'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

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

Any help?



Solution 1:[1]

I realised it. In my config file I had the baseURL as '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.

Solution 2:[2]

with strapi v4 u need to manually populate your rest api with images otherwise it's restricted due to security reasons :

localhost:1337/api/posts?populate=*

then you will get images on your endpoint

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak
Solution 2 Nsamba Isaac