I'm trying to built a small picture gallery with svelte and strapi v4 for learning purposes. I have my content type configured as shown in picture 1 (Picture 1, content type) and this is the code I use to make the get request to my strapi backend:
onMount(async () => {
try {
const response = await instance.get("/api/picture-blog-posts")
console.log(response);
} catch (e) {
error = e
}
})
I added a few pictures through the Strapi Admin Panel and published them.
I was thinking, that I would get the image url as an attribute, but I don't:
The data response I get.
I am not sure what I am supposed to different or where my problem is, because the response has all the data except the image data :/
So help will be very much appreciated.
Also I will gladly add more details, if you think they are needed. Just trying to keep it concise...
To improve performance, Strapi V4 doesn’t return media files or relation data by default. Thus, you will need to adapt your request as it is outlined in the docs:
Example with using axios and qs:
const query = qs.stringify({
populate: '*',
fields: '*',
publicationState: 'live',
locale: ['en','de'],
}, {
encodeValuesOnly: true, // prettify url
});
const url =`${REPLACEWITHYOURBASEURL}/api/settings-header?${query}`;
const result = await axios.get(url);