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...
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
filefield 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:
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-liborpdf-poppler - Third-party services like Cloudinary or imgix that support PDF thumbnail generation
- A serverless function (could use Sanity Functions) to process the PDF with libraries like
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.
Client-side rendering - Use a browser-based PDF renderer like
pdf.jsto generate thumbnails on-demand in your frontend applicationHybrid approach - Store PDFs in Sanity but use a separate document type that includes both a
filefield (for the PDF) and animagefield (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.
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.