Strapi 5

Provider documentation

Strapi 5

Select a Strapi media format with fallback to smaller available variants.

Setup

Install the framework package and the core package for the provider import:

npm install @desource/image @desource/image-svelte

Save this as image.config.ts beside your example component. Replace sample domains and identifiers with your own.

import type { ImageConfig } from '@desource/image';
import { strapi5Provider } from '@desource/image/providers/strapi5';

export const imageConfig = {
  provider: 'strapi5',
  providers: {
    strapi5: strapi5Provider({
      "baseURL": "https://cms.example.com/uploads"
    })
  }
} satisfies ImageConfig;

Registering this provider makes it the default for the configured components. To mix services, register each provider and set provider="strapi5" on the image that should use this one.

Image source

Use the upload URL/path and pass the asset formats object as a modifier.

/uploads/photo_hash.jpg

Usage

The example uses the shared configuration above and the Svelte image component.

<script lang="ts">
  import { Image, setImageConfig } from '@desource/image-svelte';
  import { imageConfig } from './image.config';

  setImageConfig(imageConfig);
</script>

<Image
  src="/uploads/photo_hash.jpg"
  alt="Sample image" width={800} height={500}
  modifiers={{
  "breakpoint": "medium",
  "formats": {
    "medium": {
      "url": "/uploads/medium_photo_hash.jpg"
    },
    "small": {
      "url": "/uploads/small_photo_hash.jpg"
    }
  }
}}
/>

Provider options

baseURL
Upload root. Defaults to http://localhost:1337/uploads.

Pass shared defaults such as screens, domains, aliases and presets to the image configuration. Pass provider-specific defaults as modifiers in the provider factory.

Modifiers

Use breakpoint, formats and optional breakpoints. Default order is large, medium, small, thumbnail. Selection starts at the requested breakpoint and tries subsequent formats.

Set dimensions on the component and pass service-specific operations through modifiers, as shown above. See the provider source for exact mappings and the service documentation for accepted values.

Provider notes

  • Missing breakpoint or formats returns the original. If no matching variant exists, the original is also returned.
  • The leading /uploads/ path is removed before joining baseURL. Width, height, quality and format do not generate new files.
← Back to all providers