Hi. Specific to `file` types like PDF, does Sanity Studio offer the ability to generate a thumbnail of the PDF, similar to what is done on image uploads? Or is that functionality...

3 replies
Last updated: Oct 23, 2020
Hi. Specific to
file
types like PDF, does Sanity Studio offer the ability to generate a thumbnail of the PDF, similar to what is done on image uploads? Or is that functionality something people have to develop on their own using a separate backend/storage?
AI Update

Sanity Studio doesn't automatically generate thumbnails for PDF files the way it does for images. This is a feature you'll need to implement yourself using a separate backend or service.

Here's what's happening and your options:

Out of the box:

  • When you upload an image to Sanity, you get automatic thumbnail generation and the full Sanity Image API for transformations
  • When you upload a PDF (or other file types) using the file field type, Sanity stores it as-is with metadata like filename, size, and MIME type, but doesn't generate preview thumbnails

Common approaches for PDF thumbnails:

  1. Custom asset source plugin - Create a Studio plugin that intercepts PDF uploads, generates a thumbnail (first page as an image), and stores both the PDF and thumbnail. You'd typically use a service like:

    • A serverless function (could use Sanity Functions) to process the PDF with libraries like pdf-lib or pdf-poppler
    • Third-party services like Cloudinary or imgix that support PDF thumbnail generation
  2. Post-processing with webhooks or Functions - Use Sanity Functions to listen for file upload events, generate thumbnails server-side, and store the thumbnail URL back in your document. Functions are the modern, recommended approach since they're serverless compute built directly into Sanity.

  3. Client-side rendering - Use a browser-based PDF renderer like pdf.js to generate thumbnails on-demand in your frontend application

  4. Hybrid approach - Store PDFs in Sanity but use a separate document type that includes both a file field (for the PDF) and an image field (for a manually uploaded or programmatically generated thumbnail)

The reason Sanity doesn't do this automatically is that PDF processing is computationally expensive and use cases vary widely (which page to preview, resolution needed, etc.). Most teams end up building custom solutions that fit their specific needs.

We currently don’t support this out of the box, so it would have to be handled separately! Feel free to create a feature request for it tho 😊 https://github.com/sanity-io/sanity/issues
Thanks for the follow up
user H
.
I posted up my official request here:
https://github.com/sanity-io/sanity/issues/2091

🤞
No problem, and thank you!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?