Media

Technical reference for configuring media asset providers.

Netlify Create can work with any media provider you choose to use, which tend to fall into one of three categories:

API CMS

If your project is configured to work with API-based CMS (Contentful, Sanity, etc.), your assets will be stored in that CMS.

Netlify Create knows how to work with media from headless CMS providers. All you need to do is configure the content source appropriately using the contentSource property. The best way to do this is to find the appropriate integration guide.

Media Providers

Use of media providers is limited to paid plans.

Regardless of your content source, you have the option to use a third-party media provider. These services are configured through the Netlify Create application. See below for supported providers:

If your preferred media provider is not listed, please contact us for details on supporting your service. Or, consider a looser integration by creating a custom asset source.

Custom Asset Sources

In cases where there isn't a direct integration with an asset provider and where you want to use a different asset source than what is provided by the content source, you can use the assetSources property to bring your own behavior.

assetSources

Defines a custom source to be used selectively by image fields.

This is currently referring specifically to custom iframe sources. Other third-party sources are available as direct integrations. See the integration guides for usage information.

Required
No
Options

type (required): How the selection modal should be rendered. Options: iframe

name (required): Unique name for the source, which is then used by the source property within image field definitions.

url (required): URL to the page to be rendered within the selection modal's <iframe> element. This page must be built to send image information back to Netlify Create via the postMessage method, which can then be used by the transform function.

preview (required): How to render the image when it is shown in a Netlify Create form field. This should be specified as an object with the following properties:

  • image (required): URL of the image to render.
  • title: Display label for the image (not currently being used).

The object can be defined directly, or as the return value of a function that receives an object with an assetData property, containing the data stored in the source (i.e. the data resulting from the transform method, if used). See below for a usage example.

transform: A function receiving an object with an assetData property, set to the content received from the iframe source, via the postMessage method.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
import { defineStackbitConfig } from '@stackbit/types'

export default defineStackbitConfig({
  stackbitVersion: '~0.6.0',
  contentSources: [
    // ...
  ],
  assetSources: [
    {
      name: 'asset-source-name',
      type: 'iframe',
      url: 'https://www.asset-source-url.com',
      transform: ({ assetData }) => assetData.imageUrl,
      preview: ({ assetData }: { assetData: string }) => ({ image: assetData }),
    },
  ],
  modelExtensions: [
    {
      name: 'hero',
      type: 'object',
      fields: [{ name: 'image', type: 'image', source: 'asset-source-name' }],
    },
  ],
})

Storing Media in Repository

If you're using files as your content source (Git CMS), you can also choose to store media files within your repository. Use the assets property (documented below).

assets (deprecated)

Media should be configured using the Git CMS module.

The assets object defines where local site assets are stored in your project, and how other content references these assets.

Required
When using files content source (Git CMS) and storing assets in the repository
Options

referenceType (required): Specifies how content files reference asset files. Options: static, relative.

uploadDir (required): Path inside assetsDir in which to store uploaded assets, relative to either staticDir (for static assets) or assetsDir (for relative assets).

Additional properties for static assets:

  • staticDir: Directory path relative to the project root in which the site framework copies files to the directory that get deployed.

  • publicPath: URL from which the static files are publicly available.

Additional properties for relative assets:

  • assetsDir: Path to the directory containing all the assets to your project, relative to the project root.

Static Assets

Here's an example configuration for this object using static assets. This is a common configuration when using Next.js.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
export default {
  cmsName: 'git',
  assets: {
    referenceType: 'static',
    staticDir: 'public',
    uploadDir: 'images',
    publicPath: '/',
  },
  // other properties ...
}
  • All assets must be placed under the directory set in staticDir, either directly or in subdirectories. They cannot be colocated with page content or source code. The value is always relative to the root of the project.
  • When the build is run, assets are served from the URL path set by publicPath. The full URLs are constructed as {publicPath}/{file path under staticDir}.
  • With the example configuration above, an image file named public/creatives/car.png in your repository will be served from the URL /creatives/car.png.
  • Images uploaded by editors would be saved in {staticDir}/{uploadDir}, or in the above case: {root}/public/images.

Relative Assets

Gatsby is a framework in which asset files can be colocated with content, rather than under a single dedicated directory, allowing content to make use of relative assets.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
export default {
  cmsName: 'git',
  assets: {
    referenceType: 'relative',
    assetsDir: 'src',
    uploadDir: 'images',
  },
  // other properties ...
}
  • assetsDir can include files of different types. However, only files with specific extensions will be treated as assets (png, jpg, jpeg, gif, svg, ico, etc.).
  • Images uploaded by editors would be saved in {assetsDir}/{uploadDir}, or in the above case: {root}/src/images.