API json response does not return my uploaded image

I just set up my first collection “images” which just holds images i uploaded with the media library. When i access the public api like “http://mydomain.com/api/images/1” it returns the following json:

{"data":{"id":1,"attributes":{"createdAt":"2021-12-03T10:10:04.861Z","updatedAt":"2021-12-03T10:22:20.847Z","publishedAt":"2021-12-03T10:22:20.845Z"}},"meta":{}}

Where is the image url? Why is it not returned with the get request? Every fieldtype is returned except the images…i could not find any ressources on this issue so far and it is driving me crazy.

After further investigation i found that there is no reference inside the data.db (sqlite) between the files table and images table…i suspected that would be made automatically once i create the collection type?

3 Likes

I have the same problem. Did you find any solution?

I’m having this exact same problem with attributes, particilarly media files. This is the first post that I’ve seen directly related to it.

To improve performance, Strapi V4 doesn’t return media files or relation data by default. Now you have to specifically include it in your api request as is outlined in the docs -
Content API Docs.

They don’t specifically mention images in their examples, but querying for them with this method works. To just return the full response as you would have gotten in V3, you can just use /api/images/1?populate=* to have the api return all the fields.

Hope this helps!

8 Likes

Awesome - thank you for the explaination. I did not know of the (breaking?) changes from v3 to v4. Most of the videos are still on v3 where it just works out of the box. Performance wise is sound totally reasonable though.

Is there any way to populate all the images using query engine api when we have complex data structure e.g. component within component inside dynamic zone?

1 Like

http://localhost:1337/api/reviews?populate=*
you can do like this for get all the images in query params ?populate=*

It looks like you’re having trouble with your API json response not returning the uploaded image. I’m not exactly sure what could be causing this issue, but have you tried checking if there are any errors in your code? You could also try consulting the documentation for the API or reaching out to their support team for assistance.
I think you should also check out uat testing meaning. UAT testing, or user acceptance testing, is a process of verifying that a software system meets the end users’ requirements and that it is ready for release. This might be what you need.

case you are using Single Type with Component type Repeatable Component try this:
/api/news?populate=Items.Icon

example body json:

{
	"data": {
		"id": 1,
		"attributes": {
			"createdAt": "2023-08-04T19:31:10.868Z",
			"updatedAt": "2023-08-04T21:49:31.068Z",
			"publishedAt": "2023-08-04T19:31:23.367Z",
			"Items": [
				{
					"id": 4,
					"Title": "Title Content example",
					"Description": "Description Content example",
					"Color": "Blue",
					"UrlRelacionada": "url related example",
					"Icon": {
						"data": {
							"id": 3,
							"attributes": {
								"name": "Sino.svg",
								"alternativeText": "Sino",
								"caption": null,
								"width": 24,
								"height": 24,
								"formats": null,
								"hash": "Sino_ff39ea462b",
								"ext": ".svg",
								"mime": "image/svg+xml",
								"size": 0.36,
								"url": "/uploads/Sino_ff39ea462b.svg",
								"previewUrl": null,
								"provider": "local",
								"provider_metadata": null,
								"createdAt": "2023-08-04T19:08:19.737Z",
								"updatedAt": "2023-08-04T19:08:19.737Z"
							}
						}
					}
				}
			]
		}
	},
	"meta": {}
}
2 Likes

Hi, @gabriel-prog! Thanks, it works

1 Like

Here is additional helpful resource in this article that explains populate and filtering in Strapi.

Article: Demystifying Strapi's Populated & Filtering

And best practices video on populate and filtering: https://youtu.be/aJ2pYRN8DH0

Perfeito!! Muito obrigado, ajudou demais!