Search code examples
strapi

Media files not showing in API with Strapi


I have created a component with a media field. When I upload an image/video I can’t see it in the API. I’ve even tried using ?populate=*. What can I be missing?

enter image description here


Solution

  • The populate=* give’s you the first level of relations so you get only component, but not the relation included in component.

    I’m not sure what is your model looks like, what would give some more info how to properly write query, you have two options:

    The easiest solution is: yarn add strapi-plugin-populate-deep /api/pages/1?populate=deep

    harder one is to use qs with something like:

    const str = qs.stringify(
      {
        populate: { hero: { populate: ["media", "heroImage"] } }
      },
      { encodeValuesOnly: true }
    );
    

    witch would give you:

    populate[hero][populate][0]=media&populate[hero][populate][1]=heroImage