File Preview
Let users look inside a file without downloading it, with a predictable fallback for every type the product can't render.
6 states5 edge casesDesktop + Mobile
01The problem
Users attach files to find them again and check them quickly: is this the signed version, which receipt is this? Downloading every file to check it is slow, clutters the device and doesn't work well on mobile. Previews remove that friction, but only if they handle the files the product can't render as gracefully as the ones it can.
02When to use
Use when
- Attachments on records: invoices, contracts, receipts, images
- File libraries where users browse many files
- Review workflows where users check documents before approving
Avoid when
- Files that need editing — open them in the editor or the native app instead.
- Sensitive files where your policy forbids rendering in the browser.
03Recommended UX
Statecraft recommendation
Open previews in an overlay on top of the current page, with name, size, Download and close always visible, and arrow navigation between files in the same set. For types you can't render, show a clear file card with Download instead of an error.
An overlay keeps the user's place: they glance at the file and return to the list or record without reloading.
Navigating with arrow keys through a set of receipts turns ten open-close cycles into one review.
Unsupported types are normal, not errors. A card with type, size and Download is the honest preview of a .sketch file.
04Interaction flow
- 01
File list or thumbnails
Type icon, name, size; thumbnail for images and PDFs.
- 02
Open preview
Overlay with header: name, size, Download, close.
- 03
Render by type
Image, PDF, video, text — or a fallback card.
- 04
Navigate set
Previous / next through files in the same list.
Result
- Viewed
- Downloaded
- Unsupported card
05Desktop behaviour
On desktop the preview is a large overlay that dims the page, with the file centred and navigation controls at the edges.
Desktop rules
- Header: file name, size, position (“2 of 5”), Download, Open in new tab, Close.
- Left / right arrow keys and edge buttons move through the set; Escape closes.
- Zoom for images and PDFs, starting at fit-to-screen.
- Show the first PDF page fast and load the rest progressively.
06Mobile behaviour
On mobile the preview is full-screen with native gestures: swipe between files, pinch to zoom, swipe down to close.
Mobile rules
- Full-screen viewer with a minimal header that hides on tap.
- Swipe horizontally between files; pinch to zoom images and PDFs.
- Share / Download through the native share sheet.
- For large files on cellular, show size and ask before loading video.
07States
Thumbnail
Image or first page preview in the list; type icon fallback.
Loading
Header appears instantly; content area shows progress for large files.
Rendered
File shown at fit-to-screen with zoom controls.
Unsupported type
Card with icon, name, type, size and Download.
Processing
Preview still being generated after upload: “Preview ready in a moment”.
Failed
Couldn't load; Retry and Download still available.
08Edge cases
EC-01
Very large file
A 400-page, 120 MB PDF.
Recommendation
Render page by page as the user scrolls and show the page count up front. Never block on downloading the whole file.
EC-02
Preview not generated yet
The user opens a file uploaded 3 seconds ago.
Recommendation
Show “Preparing preview…” with Download available, and swap in the preview automatically when it's ready.
EC-03
Malicious or active content
An uploaded SVG or HTML file contains scripts.
Recommendation
Serve user files from a separate domain with download headers, and render SVG and HTML as images or text, never inline in your app's origin.
EC-04
Expired link
The preview has been open for an hour and the signed URL expired.
Recommendation
Refresh the URL silently on the next load or download; don't show an access error for an expiry the user didn't cause.
EC-05
File deleted while viewing
Someone else deletes the file during preview.
Recommendation
Keep the current view, show “This file was deleted by Dana”, and disable navigation to it.
09Microcopy
Unsupported
Avoid
“Preview not available”
Prefer
“No preview for .sketch files. Download (4.2 MB)”
Processing
Prefer
“Preparing preview… You can download it now.”
Failed
Avoid
“Error loading file”
Prefer
“Couldn’t load the preview. Retry or download the file.”
Position
Prefer
“receipt-march.png · 2 of 5”
10Accessibility
- The preview is a modal dialog labelled with the file name; focus moves into it and returns to the opened item on close.
- Previous / Next buttons name the destination file.
- Images need alt text: the file name at minimum, or a user-supplied description.
- Zoom controls are buttons, not gesture-only, on desktop.
11Developer notes
- 01
Generate thumbnails and preview renditions asynchronously after upload, and store their status per file.
- 02
Serve files via short-lived signed URLs from a separate domain with Content-Disposition and strict Content-Type.
- 03
Use a type-to-renderer map with a fallback card so new types degrade instead of breaking.
- 04
Preload the adjacent file in the set for instant navigation.
12Implementation prompt
For Claude Code, Codex or Cursor
Implement a file preview overlay.
Requirements:
- Open from file lists and thumbnails as a modal dialog; Escape closes; focus returns to the opened item.
- Header: name, size, "2 of 5", Download, Open in new tab, Close.
- Previous/next through the current file set with arrow keys and edge buttons; preload neighbours.
- Renderer map by type: image (zoom), PDF (progressive pages, zoom), video, plain text; fallback card for everything else with Download.
- States: loading, rendered, processing ("Preparing preview…"), unsupported, failed (Retry + Download).
- Files served from a separate domain via short-lived signed URLs; refresh expired URLs silently; never render SVG/HTML inline in the app origin.
- Mobile: full-screen viewer, swipe between files, pinch zoom, swipe down to close, native share.
Do not redesign the existing interface.