Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve custom image metadata #6

Closed
geoffdavis92 opened this issue Aug 12, 2019 · 3 comments
Closed

Retrieve custom image metadata #6

geoffdavis92 opened this issue Aug 12, 2019 · 3 comments

Comments

@geoffdavis92
Copy link

Is there a way to retrieve custom image metadata from Cloudinary images?

This would be beneficial if users programmatically add metadata key/value pairs to media uploads.

@5un
Copy link

5un commented Feb 21, 2020

If you're still interested. Passing context: true option in gatsby-config.js works for me. It is also part of the Cloudinary node.js api spec.

My gatsby-config.js config block

{
      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`,
        maxResults: `200`,
        context: true,
   }
}
query MyQuery {
  allCloudinaryMedia(limit: 10) {
    edges {
      node {
        id
        url
        secure_url
        public_id
        context {
          custom {
            alt
            caption
          }
        }
      }
    }
  }
}

I get custom.alt, custom.caption from what I've set as the Title and Description of the image in Cloudinary. However, I could not get custom fields to work with this method.

@Chuloo
Copy link
Collaborator

Chuloo commented May 11, 2020

Thanks for this @5un

@Chuloo Chuloo closed this as completed May 11, 2020
@donaldboulton
Copy link

Try This

function ImageGallery({ image, thumb, group, ...rest }) { const data = useStaticQuery(graphql
query CloudinaryImage {
allCloudinaryMedia(sort: {fields: tags, order: ASC}) {
edges {
node {
public_id
resource_type
secure_url
tags
context {
custom {
alt
caption
}
}
}
}
}
}
) const clImages = data.allCloudinaryMedia.edges

then link to image
{image.node.secure_url}

link to alt or caption

{image.node.context.custom.caption}

props

ImageGallery.propTypes = { image: PT.string.isRequired, thumb: PT.string, group: PT.string.isRequired };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants