Images in the content of categories
· 2 min read
The HTML content of categories (body_html) now stores its images in the store's media library, as the content of blog posts already does.
Images in body_html
When a category is created or updated through the API, the images of body_html in each locale are handled the same way as in blog posts:
- External images (
<img>) are downloaded to the store's media library (Images and documents), and the saved content points to the stored copy. An image that was already downloaded is reused, and images already hosted by the store are not downloaded again. - Embedded base64 images (
data:URIs) are also stored in the media library, and the same image is reused if it is sent again. - Up to 50 external images can be downloaded per request, adding up the content of all the locales sent, and image URLs cannot be longer than 1000 characters.
- If an image cannot be downloaded, the request fails with a descriptive error for that locale and nothing is saved:
{
"translations": {
"en-GB": {
"body_html": [
"Image \"https://example.com/missing.png\": The server responded with status 404."
]
}
}
}
Content that only uses images already hosted by the store is saved as it is sent.
Where each file is used
In the backoffice, the media library shows where each file is used, so that nobody deletes an image that is still shown in the store. Categories are now included, whatever the way their content is saved: the backoffice editor, the API, CSV imports or automatic translations.
Availability
POST /api/v1/categories/andPATCH /api/v1/categories/{id}/(body_html)

