# Sirv plugin for Storyblok

![Storyblok logo](https://sirv.sirv.com/website/storyblok-logo.png?w=230)

Browse, search and pick media from your Sirv account without leaving the Storyblok editor.

Using an AI coding agent?

Install the [`image-optimization`](https://www.skills.sh/sirv/image-optimization-skill/image-optimization) skill, and your agent can set up Sirv images in your project. Ask in plain words, such as “Serve our product images from Sirv and make them load faster.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

The Sirv field plugin for Storyblok adds a full Sirv DAM browser to your content blocks.

Editors pick **images**, **videos**, **[360 spins](/help/spin/getting-started/how-spin-files-are-created/)**, **[Sirv Media Viewer](/help/sirv-media-viewer/)** assets and **[3D models](/help/sirv-media-viewer/media-types/3d-model/)** (glTF/GLB) from Sirv.

Your frontend delivers them through Sirv’s global CDN, resized, optimized and in the best format for every visitor.

[Alt text](/help/image-management/add-alt-tags-images-automatically-ai/) and captions are filled in automatically from your Sirv asset metadata, and galleries support multi-select and drag-to-reorder.

The plugin ships with **zero embedded credentials**. Each editor connects with their own Sirv [REST API](/help/rest-api/sirv-rest-api/) key, which never touches your content or the plugin code.

## Requirements

-   A [Sirv account](https://app.sirv.com/signup) (free or paid) and its REST API **Client ID** and **Client Secret** from [Settings > API access](https://app.sirv.com/settings/api).
-   A Storyblok account. To deploy the plugin you also need Node.js 18.15+ and pnpm 10+ on your computer.

## Installation

The plugin is deployed to your Storyblok account with Storyblok’s Field Plugin CLI. You do this once; afterwards it appears as a custom field type named `sirv-dam` in every space you own.

1.  Clone the repository and install dependencies:
    
    ```bash
    git clone https://github.com/ishugurov/sirv-storyblok.git
    cd sirv-storyblok
    pnpm install
    ```
    
2.  Create a Storyblok personal access token at [My account > Personal access tokens](https://app.storyblok.com/#/me/account?tab=token). When generating it, tick **“Full user permission (no scope/space restriction)”**.
    
    Tokens generated with selected scopes cannot deploy plugins. The plugins API rejects them, because plugins are account-level and no plugin scope exists.
    
3.  Save the token in `apps/storyblok-plugin/.env` (this file is gitignored):
    
    ```bash
    STORYBLOK_PERSONAL_ACCESS_TOKEN=your-token-here
    ```
    
4.  Deploy:
    
    ```bash
    pnpm --filter @sirv/storyblok-plugin run deploy
    ```
    

The plugin is uploaded and published to **My account > My Plugins** as `sirv-dam`.

Re-run the same command any time to publish an update (hard-refresh the Storyblok editor afterwards - it caches the plugin bundle).

## Add the Sirv field to a block

The Sirv picker is added to your content as a field of type **Plugin** on any block. You can add it to a brand new block or to a block you already use.

### Create a new block

1.  In your Storyblok space, open **Block Library** from the left sidebar.
    
2.  Click **\+ New block** (top right).
    
3.  Enter a technical name for the block, for example `product`, choose the block type (Nestable block for components you insert into pages; Content type block for whole stories) and click **Add Block**.
    
    ![Create a new block in the Storyblok Block Library](https://sirv.sirv.com/website/screenshots/storyblok/storyblok-new-block.png?profile=screenshots-grey-border)
    

### Or edit an existing block

Open **Block Library** and click the block you want to extend - its schema editor opens on the right.

### Add the Sirv picker field

1.  In the block’s schema editor, type a field name into the **Add field** box, for example `image`, pick the field type **Plugin** and click **Add**.
    
2.  Click the new field to open its settings and set **Custom Type** to `sirv-dam`.
    
    ![Set the field type to Plugin and the Custom Type to sirv-dam](https://sirv.sirv.com/website/screenshots/storyblok/storyblok-sirv-dam-field.png?profile=screenshots-grey-border)
    
3.  Under **Options**, add key/value pairs to configure the field (see the [field options](#field-options) below). For a single image picker:
    
    ```text
    mode          single
    allowedTypes  image
    ```
    
    ![Configure the Sirv field options in the block schema](https://sirv.sirv.com/website/screenshots/storyblok/storyblok-field-options.png?profile=screenshots-grey-border)
    
4.  Click **Save schema**. Every story using this block now shows an **Add asset from Sirv** button for the field.
    

## Field options

One plugin covers every use case - the field’s behavior is set per block field with these options:

-   `mode` - what the field stores. `single` (one asset, the default), `list` (a gallery with multi-select and drag-to-reorder) or `url` (a plain URL string to any Sirv asset, including documents).
    
-   `allowedTypes` - comma-separated list of asset types the picker offers: `image`, `video`, `spin` (360 spins), `view` (Sirv Media Viewer files), `model` (glTF/GLB 3D models).
    
    Add `file` to also allow generic files such as PDFs and ZIPs (useful in `url` mode). Default: the five media types.
    
-   `renderMode` - a hint for galleries on your frontend: `separate` (each asset rendered on its own, the default) or `viewer` (all assets combined into one Sirv Media Viewer).
    
-   `rootPath` - the Sirv folder the browser opens in, e.g. `/products`. Default: your account root.
    
-   `clientId` and `clientSecret` - optional team-wide Sirv account. When both are set in the block schema, editors skip the connect step entirely.
    
    Anyone who can read the block schema can see the secret. Prefer the per-editor connect flow unless you specifically want one shared, admin-managed account.
    
-   `deliveryAlias` - the delivery domain for the shared account, e.g. `yourcompany.sirv.com` (used with `clientId`/`clientSecret`).
    

Example configurations:

```text
A gallery of images and videos, rendered as one combined viewer:
  mode          list
  allowedTypes  image,video
  renderMode    viewer

A download link to any file in your /docs folder:
  mode          url
  allowedTypes  file
  rootPath      /docs
```

## Connect your Sirv account

The first time an editor opens the picker, the plugin asks for Sirv REST API credentials:

1.  In a story, click **Add asset from Sirv**. The Sirv media library opens.
    
2.  Paste your **Client ID** and **Client Secret** from [app.sirv.com > Settings > API access](https://app.sirv.com/settings/api) and click **Connect**.
    
3.  Choose the delivery domain to serve assets from (if your account has more than one).
    
    ![Connect your Sirv account inside the Storyblok editor](https://sirv.sirv.com/website/screenshots/storyblok/storyblok-sirv-connect.png?profile=screenshots-grey-border)
    

The credentials are stored only in that editor’s browser (scoped to the Storyblok space) - never in your content, the plugin bundle or the repository.

The connection is reused silently afterwards; use the logout icon in the media library header to disconnect or switch accounts.

## Using the picker

Once connected, the media library shows your Sirv folders and files:

-   **Browse** folders with the breadcrumb trail, or **search** your entire account by filename.
    
-   **Filter chips** narrow results to images, videos, 360 spins, viewer files or 3D models.
    
-   Click an asset to **preview** it, then click **Use this asset**. Spins, viewer files and 3D models load live (drag to rotate or orbit), and videos play.
    
    Or click the **+** button on a thumbnail to add it instantly without the preview step.
    
-   In `list` mode, click several assets (across folders and searches) and add them together. Reorder the gallery afterwards by dragging items; an insertion line shows exactly where each item will land.
    

![Browse and pick Sirv assets in the Storyblok editor](https://sirv.sirv.com/website/screenshots/storyblok/storyblok-dam-browser.png?profile=screenshots-grey-border)

When an image or video is picked, its **alt text** and **caption** are filled in automatically from the asset’s title and description in Sirv.

Editors can adjust them - plus image quality and video playback options - right in the field.

## What gets stored

The field saves plain JSON in your story - no Storyblok asset duplication, the media stays on Sirv:

```js
{
  "_type": "sirvMedia",
  "mediaType": "image",
  "sirvPath": "/products/shoe.jpg",
  "sirvAlias": "yourcompany.sirv.com",
  "originalUrl": "https://yourcompany.sirv.com/products/shoe.jpg",
  "width": 2000,
  "height": 1890,
  "alt": "Red running shoe",
  "caption": "Side view"
}
```

`list` mode stores an array of these objects; `url` mode stores a plain URL string.

## Rendering on your frontend

Fetch the story from Storyblok’s Content Delivery API as usual, then render the stored values with the [@sirv/react](https://www.npmjs.com/package/@sirv/react) components.

They build responsive, optimized Sirv URLs and load sirv.js automatically for spins and viewers:

```tsx
import {
  SirvProvider,
  SirvMedia,
  SirvGallery,
  fromSanityMedia as fromStoredMedia,
} from '@sirv/react';

<SirvProvider alias="yourcompany.sirv.com">
  <SirvMedia value={fromStoredMedia(story.content.image)} width={640} />
  <SirvGallery
    items={story.content.gallery.map(fromStoredMedia)}
    layout="viewer"
    width={640}
    height={480}
  />
</SirvProvider>
```

3D models are rendered by sirv.js rather than a `@sirv/react` component - drop the model URL into a `.Sirv` container:

```html
<div class="Sirv" data-src="https://yourcompany.sirv.com/models/chair.glb"></div>
```

A complete Next.js example, including live fetching from the Content Delivery API and a 3D-model section, is in the `examples/next` folder of the repository.

## Common questions

Can the Sirv picker replace Storyblok's native Asset field?

No. Storyblok does not let third parties hook into its native Asset field - every external DAM (Bynder, Cloudinary, Frontify and others) integrates the same way, as a custom Plugin field. Use a field of type Plugin with the sirv-dam custom type instead of the native Asset field.

Where are my Sirv credentials stored?

In your browser's local storage, scoped to the Storyblok space. They are never written into your content, the plugin bundle or the repository. Optionally, a team-wide account can be configured by an admin via the clientId and clientSecret options in the block schema.

Which media types does the plugin support?

Images, videos, 360 spins, Sirv Media Viewer (.view) files and 3D models (.glb/.gltf) in all modes, plus generic files such as PDFs and ZIPs when "file" is added to allowedTypes (typically in url mode).

I deployed a new plugin version but the editor still shows the old one.

The Storyblok editor caches the plugin bundle. Hard-refresh the editor page (Cmd+Shift+R or Ctrl+Shift+R) after deploying an update.
