最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Strapi api doesn't return image field - Stack Overflow

programmeradmin1浏览0评论

I'm in a pretty strange situation.

the url /api/home-page?populate=* doesn't return my image field but /api/home-page?populate=heroImage does

On the other side I have another single page very similar where populate=* and populate=heroImage are both working fine.

What can explain that problem?

Below the two schema.json

home-page :

{
  "kind": "singleType",
  "collectionName": "home_pages",
  "info": {
    "singularName": "home-page",
    "pluralName": "home-pages",
    "displayName": "Page d'accueil",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "description": {
      "type": "text"
    },
    "seo": {
      "type": "component",
      "repeatable": false,
      "component": "shared.seo"
    },
    "heroImage": {
      "type": "media",
      "multiple": false,
      "required": false,
      "allowedTypes": ["images"]
    },
    "img": {
      "allowedTypes": ["images"],
      "type": "media",
      "multiple": false
    }
  }
}

the other page :

{
  "kind": "singleType",
  "collectionName": "ou_trouver_bonuxes",
  "info": {
    "singularName": "ou-trouver-bonux",
    "pluralName": "ou-trouver-bonuxes",
    "displayName": "Où trouver Bonux"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "description": {
      "type": "text"
    },
    "heroImage": {
      "allowedTypes": [
        "images"
      ],
      "type": "media",
      "multiple": false
    }
  }
}

I'm in a pretty strange situation.

the url /api/home-page?populate=* doesn't return my image field but /api/home-page?populate=heroImage does

On the other side I have another single page very similar where populate=* and populate=heroImage are both working fine.

What can explain that problem?

Below the two schema.json

home-page :

{
  "kind": "singleType",
  "collectionName": "home_pages",
  "info": {
    "singularName": "home-page",
    "pluralName": "home-pages",
    "displayName": "Page d'accueil",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "description": {
      "type": "text"
    },
    "seo": {
      "type": "component",
      "repeatable": false,
      "component": "shared.seo"
    },
    "heroImage": {
      "type": "media",
      "multiple": false,
      "required": false,
      "allowedTypes": ["images"]
    },
    "img": {
      "allowedTypes": ["images"],
      "type": "media",
      "multiple": false
    }
  }
}

the other page :

{
  "kind": "singleType",
  "collectionName": "ou_trouver_bonuxes",
  "info": {
    "singularName": "ou-trouver-bonux",
    "pluralName": "ou-trouver-bonuxes",
    "displayName": "Où trouver Bonux"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "description": {
      "type": "text"
    },
    "heroImage": {
      "allowedTypes": [
        "images"
      ],
      "type": "media",
      "multiple": false
    }
  }
}
Share Improve this question asked Nov 18, 2024 at 12:41 Rom-888Rom-888 8862 gold badges14 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

With the populate=* parameter, it returns first-level relations, components and dynamic zones.

You can use Strapi deep populate plugin. Install the plugin

npm i strapi-plugin-populate-deep

and make the requests like

/api/articles?populate=deep
发布评论

评论列表(0)

  1. 暂无评论