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

Support previewing asset types other than video and images #71

Open
sarmeyer opened this issue Feb 20, 2024 · 2 comments
Open

Support previewing asset types other than video and images #71

sarmeyer opened this issue Feb 20, 2024 · 2 comments

Comments

@sarmeyer
Copy link

sarmeyer commented Feb 20, 2024

Is your feature request related to a problem? Please describe.
There's currently no way to preview an asset type that isn't a video or image. This has come up when adding raw asset types. They aren't caught by the first condition in src/components/AssetPreview.tsx and so a preview is attempted with an img tag, but there are other resource_types available that won't preview properly with the default return value

image
(this particular asset is .doc type, but this happens with other formats like pdfs)

Describe the solution you'd like
Add another condition to render resource types other than images or videos, or allow the consumer to define their own preview config

Describe alternatives you've considered
I'm considering recreating the cloudinary asset schema type for the instances where files or other raw assets types are often used, so that we can define our own preview config, but this is not an ideal solution

@dubhue
Copy link

dubhue commented Mar 4, 2024

It would be nice to be able to pass in/use a customized AssetPreview component that had access to the Cloudinary schema, so one could customize the preview with either text or perhaps a transformed version of the asset if it is a convertible but not tag supported image type.

@aadgrant
Copy link

aadgrant commented Jul 31, 2024

I solved this by creating a component:

(Note that I'm using typescript not javascript so please adjust as needed!)

/components/cloudinaryPreviewImage.tsx

export default (url?: string, alt?: string) => (<img src={url?.replace('image/upload', 'image/upload/c_thumb,w_32,g_face,q_auto,f_auto')} alt={alt} />)

And then when I require a preview image:

/schemaTypes/my-new-type.ts

import previewCloudinaryImage from "../components/previewCloudinaryImage";

export const myNewType = defineType({
  name: "myNewType",
  type: "document",
  fields: [
    defineField({
      name: "title",
      type: "string,
    }),
    defineField({
      name: "image",
      type: "cloudinary.asset",
    }),
  ],
  preview: {
    select: {
      title: 'title',
      media: 'image.url',
    },
    prepare: ({ title, media }) => ({
      title,
      media: previewCloudinaryImage(media, title)
    })
  },
}

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

No branches or pull requests

3 participants