Pull data from your Cloudinary account into the Gatsby data layer with gatsby-source-cloudinary. Creates a CloudinaryMedia node for each media file found.
gatsby-plugin-imagecompatible when used withgatsby-transformer-cloudinary.- To upload images already in the Gatsby data layer (such as local files) to Cloudinary use
gatsby-transformer-cloudinary.
Β
- π Getting Started
- πΌοΈ Use with Gatsby Image
- π Pugin Options
β οΈ Gotchas- π Other Resources
- π΄ββ οΈ Contribute
Β
npm install gatsby-source-cloudinaryor
yarn add gatsby-source-cloudinaryAdd gatsby-source-cloudinary to the plugin array in your gatsby-config.js file.
module.exports = { plugins: [ { resolve: `gatsby-source-cloudinary`, options: { cloudName: process.env.CLOUDINARY_CLOUD_NAME, apiKey: process.env.CLOUDINARY_API_KEY, apiSecret: process.env.CLOUDINARY_API_SECRET, // resourceType: `image`, // type: `twitter`, // maxResults: 22, // tags: true, // context: true, // prefix: `demo/animals` }, }, ], };process.env
import React from 'react'; import { graphql } from 'gatsby'; export default function BasicPage({ data }) { return ( <main> {data.allCloudinaryMedia.nodes.map((media, index) => ( <img key={index} width="200px" src={media.secure_url} /> ))} </main> ); } export const query = graphql` query { allCloudinaryMedia { nodes { secure_url } } } `;Β
To use gatsby-plugin-image with your CloudinaryMedia nodes, you need the gatsby-transformer-cloudinary to add the gatsbyImageData resolver needed.
npm install --save gatsby-transformer-cloudinary gatsby-plugin-imageor
yarn add --save gatsby-transformer-cloudinary gatsby-plugin-imagemodule.exports = { plugins: [ { resolve: `gatsby-source-cloudinary`, options: { cloudName: process.env.CLOUDINARY_CLOUD_NAME, apiKey: process.env.CLOUDINARY_API_KEY, apiSecret: process.env.CLOUDINARY_API_SECRET, // resourceType: `image`, // type: `twitter`, // maxResults: 22, // tags: true, // context: true, // prefix: `demo/animals` }, }, { resolve: `gatsby-transformer-cloudinary`, options: { // Add the `gatsbyImageData` resolver to `CloudinaryMedia` transformTypes: [`CloudinaryMedia`], }, }, `gatsby-plugin-image`, ], };Check the gatsby-plugin-image docs and gatsby-transformer-cloudinary docs to learn more.
import React from 'react'; import { graphql } from 'gatsby'; import { GatsbyImage, getImage } from 'gatsby-plugin-image'; export default function GasbyImagePage({ data }) { return ( <main> {data.allCloudinaryMedia.nodes.map((media, index) => { const image = getImage(media); return <GatsbyImage key={index} image={image} />; })} </main> ); } export const query = graphql` query { allCloudinaryMedia { nodes { gatsbyImageData(width: 300, placeholder: BLURRED) } } } `;Β
You'll find your Cloudinary account's cloudName in your Cloudinary console.
Type: String
Default: n/a
Note: Store and retrieve your cloudName as an environment variable.
The API Key of your Cloudinary account. You'll find it in your Cloudinary console.
Type: String
Default: n/a
Note: Store and retrieve your apiKey as an environment variable.
The API Secret of your Cloudinary account. You'll find it in your Cloudinary console.
Type: String
Default: n/a
Note: Store and retrieve your apiSecret as an environment variable.
The resource types to include when pulling data from Cloudinary.
Type: String
Default: image
Valid: image, raw and video
Note: Use the video resourceType for all video and audio files, such as .mp3 and .mp4.
The storage types to include when pulling data from your Cloudinary account.
Type: String
Default: n/a
Valid: upload, private, authenticated, facebook, twitter, gplus, instagram_name, gravatar, youtube, hulu, vimeo, animoto, worldstarhiphop and dailymotion
Note: When not given, all types are sourced.
Max number of resources to return.
Type: Integer
Default: 10
When true, includes the list of tag names assigned to each resource.
Type: Boolean
Default: false
Find all resources with a public ID that starts with the given prefix sorted by public ID in the response.
Type: String
Default: n/a
Note: Can be used to source only media files from a specific folder. However, you will need to specify both type and resourceType in the config options.
When true, includes the context data assigned to each resource. Helpful in retrieving alt text or custom metadata configured for the media file in Cloudinary.
Type: String
Default: n/a
Β
- Gatsby pulls the data from Cloudinary when it builds; you need to trigger a rebuild whenever new media files are added to the Cloudinary account.
f_autoandq_autoCloudinary transformations are applied automatically to thesecure_urlvalue optimizing the delivered media quality and format.
Β
Β
Want to contribute to making the plugin even better? Feel free to send in issues and pull requests on feature requests, fixes, bugs, typos, performance lapses, or any other challenge faced using our plugin.