Thumbnails
Thumbnail Generator
The PluginThumbnailGenerator creates preview thumbnails for images and videos, providing instant visual feedback in your UI.
Usage
// Via options (recommended)
const uploader = useUploadKit({
thumbnails: true, // Enable with defaults
})
// With custom options
const uploader = useUploadKit({
thumbnails: {
width: 200,
height: 200,
quality: 0.8,
},
})
// Via plugin directly
import { PluginThumbnailGenerator } from "nuxt-upload-kit"
const uploader = useUploadKit({
plugins: [
PluginThumbnailGenerator({
maxWidth: 256,
maxHeight: 256,
quality: 0.9,
}),
],
})
Options
| Option | Type | Default | Description |
|---|---|---|---|
maxWidth | number | 200 | Maximum thumbnail width |
maxHeight | number | 200 | Maximum thumbnail height |
quality | number | 0.7 | JPEG quality (0-1) |
videoCaptureTime | number | 1 | Seconds into video to capture frame |
upload | boolean | false | Upload thumbnails to storage after main file |
How It Works
Images
- Loads the image into memory
- Calculates dimensions preserving aspect ratio
- Draws to a canvas at thumbnail size
- Exports as JPEG data URL
Videos
- Loads video metadata
- Seeks to
videoCaptureTime(or 10% of duration) - Captures the frame
- Exports as JPEG data URL
Accessing Thumbnails
After preprocessing, thumbnails are available on file.preview:
<template>
<div v-for="file in uploader.files" :key="file.id">
<img v-if="file.preview" :src="file.preview" :alt="file.name" class="thumbnail" />
<div v-else class="placeholder">No preview</div>
</div>
</template>
Skipped Files
The generator skips:
- Non-image and non-video files
- GIF files (to avoid showing only first frame)
- SVG files (vector graphics don't need thumbnails)
- Remote files without local data
Timing
Thumbnails are generated during the preprocess stage, immediately after file selection. This means:
- Thumbnails appear instantly in the UI
- No waiting for upload to complete
- Users see previews while files are queued
Video Thumbnail Timing
Control when to capture the video frame:
const uploader = useUploadKit({
thumbnails: {
videoCaptureTime: 5, // Capture at 5 seconds
},
})
The plugin automatically adjusts if the video is shorter:
- Uses
videoCaptureTimeor 10% of duration, whichever is smaller
Quality vs Size
Thumbnail data URLs are embedded in the file object. Higher quality means larger strings:
| Quality | Typical Size | Use Case |
|---|---|---|
0.5 | ~5-10 KB | Large file lists |
0.7 | ~10-20 KB | Default, balanced |
0.9 | ~20-40 KB | High quality previews |
Example: Custom Thumbnail Sizes
// Small thumbnails for grid view
const uploader = useUploadKit({
thumbnails: {
width: 100,
height: 100,
quality: 0.6,
},
})
// Large previews for detail view
const uploader = useUploadKit({
thumbnails: {
width: 400,
height: 400,
quality: 0.9,
},
})
Example: Fallback for Non-Image Files
<template>
<div v-for="file in uploader.files" :key="file.id" class="file-preview">
<!-- Image/video preview -->
<img v-if="file.preview" :src="file.preview" />
<!-- PDF icon -->
<div v-else-if="file.mimeType === 'application/pdf'" class="icon">๐</div>
<!-- Document icon -->
<div v-else-if="file.mimeType.includes('document')" class="icon">๐</div>
<!-- Generic file icon -->
<div v-else class="icon">๐</div>
</div>
</template>
After Upload
When a file is uploaded, file.preview is automatically updated to use file.remoteUrl if no thumbnail was generated. This ensures previews always work:
// Before upload: file.preview = 'data:image/jpeg;base64,...' (local thumbnail)
// After upload: file.preview = 'https://storage.com/file.jpg' (or stays as thumbnail)
Uploading Thumbnails
By default, thumbnails are only generated locally as data URLs for preview purposes. To automatically upload thumbnails to your storage provider alongside the main file, set upload: true:
const uploader = useUploadKit({
storage: myStoragePlugin,
thumbnails: {
width: 200,
height: 200,
quality: 0.8,
upload: true, // Upload thumbnails to storage
},
})
When enabled:
- Thumbnails are generated during preprocess (as before)
- After the main file uploads successfully, the thumbnail data URL is converted to a
Bloband uploaded via the storage adapter's standaloneupload()method - The thumbnail storage key is derived from the file ID with a
_thumbsuffix (e.g.,photo.jpgbecomesphoto_thumb.jpg) - The uploaded thumbnail URL and storage key are available on
file.thumbnail
uploader.on("files:uploaded", (files) => {
files.forEach((file) => {
console.log("File URL:", file.remoteUrl)
console.log("Thumbnail URL:", file.thumbnail?.url)
console.log("Thumbnail key:", file.thumbnail?.storageKey)
})
})
Thumbnail upload failures are non-fatal โ the main file upload completes successfully even if the thumbnail upload fails.
Memory Management
The plugin automatically:
- Revokes object URLs after use
- Cleans up canvas elements
- Uses efficient data URLs for thumbnails
For very large uploads (100+ files), consider using lower quality thumbnails to reduce memory usage.

