Cloudinary

​

Cloudinary is a digital asset management platform with a broad feature set, including support for responsive image generation and url based image transformation. They also provide a powerful media library UI for managing assets, and tools for organizing your assets into a hierarchy.

The Cloudinary media library integration for Netlify CMS uses Cloudinary's own media library interface within Netlify CMS. To get started, you'll need a Cloudinary account and Netlify CMS 2.3.0 or greater.

Creating a Cloudinary Account

You can sign up for Cloudinary for free. Once you're logged in, you'll need to retrieve your Cloud name and API key from the upper left corner of the Cloudinary console.
Cloudinary console screenshot

Connecting Cloudinary to Netlify CMS

To use the Cloudinary media library within Netlify CMS, you'll need to update your Netlify CMS configuration file with the information from your Cloudinary account:
1
media_library:
2
name: cloudinary
3
config:
4
cloud_name: your_cloud_name
5
api_key: your_api_key
Copied!
Note: The user must be logged in to the Cloudinary account connected to the api_key used in your Netlify CMS configuration.
Note: The Netlify CMS media library extensions for Cloudinary are not included in netlify-cms-app. If you're using netlify-cms-app, you'll need to register the media libraries yourself.

Security Considerations

Although this setup exposes the cloud_name and api_key publicly via the /admin/config.yml endpoint, this information is not sensitive. Any integration of the Cloudinary media library requires this information to be exposed publicly. To use this library or use the restricted Cloudinary API endpoints, the user must have access to the Cloudinary account login details or the api_secret associated with the cloud_name and api_key.

Netlify CMS configuration options

The following options are specific to the Netlify CMS integration for Cloudinary:
  • output_filename_only: (default: false) By default, the value provided for a selected image is a complete URL for the asset on Cloudinary's CDN. Setting output_filename_only to true will instead produce just the filename (e.g. image.jpg). This should be true if you will be directly embedding cloudinary transformation urls in page templates. Refer to Inserting Cloudinary URL in page templates.
  • use_transformations: (default: true) If true, uses derived url when available (the url will have image transformation segments included). Has no effect if output_filename_only is set to true.
  • use_secure_url: (default: true) Controls whether an http or https URL is provided. Has no effect if output_filename_only is set to true.

Cloudinary configuration options

The following options are used to configure the media library. All options are listed in Cloudinary's media library documentation, but only options listed below are available or recommended for the Netlify CMS integration:

Authentication

  • cloud_name
  • api_key

Media library behavior

Image transformations

The Cloudinary integration allows images to be transformed in two ways: directly within Netlify CMS via Cloudinary's Media Library, and separately from the CMS via Cloudinary's dynamic URL's by inserting cloudinary urls.

Transforming images via Media Library

If you transform and insert images from within the Cloudinary media library, the transformed image URL will be output by default. This gives the editor complete freedom to make changes to the image output. There are two ways to configure image transformation via media library - globally and per field. Global options will be overridden by field options.
Global configuration
Global configuration, which is meant to affect the Cloudinary widget at all times, can be provided as seen below, under the primary media_library property. Settings applied here will affect every instance of the Cloudinary widget.
1
# global
2
media_library:
3
name: cloudinary
4
output_filename_only: false
5
config:
6
default_transformations:
7
- - fetch_format: auto
8
width: 160
9
quality: auto
10
crop: scale
Copied!
Field configuration
Configuration can also be provided for individual fields that use the media library. The structure is very similar to the global configuration, except the settings are added to an individual field. For example:
1
# field
2
fields: # The fields each document in this collection have
3
- label: 'Cover Image'
4
name: 'image'
5
widget: 'image'
6
required: false
7
tagname: ''
8
media_library:
9
config:
10
default_transformations:
11
- fetch_format: auto
12
width: 300
13
quality: auto
14
crop: fill
15
effect: grayscale
Copied!

Inserting Cloudinary URL in page templates

If you prefer to provide direction so that images are transformed in a specific way, or dynamically retrieve images based on viewport size, you can do so by providing your own base Cloudinary URL and only storing the asset filenames in your content:
  • Either globally or for specific fields, configure the Cloudinary extension to only output the asset filename
1
# global
2
media_library:
3
name: cloudinary
4
output_filename_only: true
5
# field
6
media_library:
7
name: cloudinary
8
output_filename_only: true
Copied!
  • Provide a dynamic URL in the site template
1
{{! handlebars example }}
2
<img src="https://res.cloudinary.com/<cloud_name>/<resource_type>/<type>/<transformations>/{{image}}"/>
Copied!
Your dynamic URL can be formed conditionally to provide any desired transformations - please see Cloudinary's image transformation reference for available transformations.
Last modified 14d ago