Downloading Media ​
Media downloading is a crucial part of the Launchpad content pipeline. This guide will walk you through downloading and transforming media files from your content sources.
Overview ​
When you fetch content that includes media (images, videos, etc.), Launchpad can automatically:
- Detect media URLs in your content
- Download the files locally
- Update content references to point to local files
- Transform media files (resize images, convert formats, etc.)
Basic Setup ​
First, add the mediaDownloader
plugin to your configuration:
import { defineConfig } from '@bluecadet/launchpad-cli';
import { mediaDownloader } from '@bluecadet/launchpad-content';
export default defineConfig({
content: {
plugins: [
mediaDownloader({
maxConcurrent: 4 // number of simultaneous downloads
})
]
}
});
The media downloader will automatically:
- Scan your content for media URLs
- Download files to your content directory
- Update URLs in your content to point to local files
Image Transformations ​
After downloading media, you can transform images using the sharp
plugin. This is useful for:
- Resizing images
- Converting formats
- Optimizing quality
- Applying effects
Add the sharp plugin after the media downloader:
import { defineConfig } from '@bluecadet/launchpad-cli';
import { mediaDownloader, sharp } from '@bluecadet/launchpad-content';
export default defineConfig({
content: {
plugins: [
mediaDownloader(),
sharp({
buildTransform: (transform) => transform
.resize(800, 600)
.jpeg({ quality: 80 }),
updateURLs: true
})
]
}
});
TIP
The sharp
plugin uses the powerful sharp image processing library under the hood. Check their documentation for all available transformations.
Common Transformations ​
Here are some useful image transformation examples:
// Resize to specific dimensions
sharp({
buildTransform: (t) => t.resize(800, 600)
})
// Convert to specific format
sharp({
buildTransform: (t) => t.webp({ quality: 80 })
})
// Multiple operations
sharp({
buildTransform: (t) => t
.resize(1200, 800)
.rotate(90)
.grayscale()
})
Best Practices ​
- Enable Caching: Launchpad automatically caches downloaded and transformed files
- Order Plugins Correctly: Always put
mediaDownloader
beforesharp
plugins
Troubleshooting ​
If media isn't downloading:
- Check your network connection
- Verify media URLs are accessible
- Ensure proper permissions in download directory
- Look for error messages in the console output
If transformations aren't working:
- Confirm media was downloaded successfully
- Check sharp plugin configuration
- Verify input image format is supported
- Look for transform-specific error messages
Next Steps ​
- Learn more about content plugins
- Explore sharp plugin options
- See media downloader configuration