The Buttondown CLI handles images and media files automatically, making it easy to reference local files in your emails and sync them with Buttondown’s media library.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/buttondown/cli/llms.txt
Use this file to discover all available pages before exploring further.
Media Directory
All images are stored in themedia/ directory at the root of your newsletter folder:
How Media Sync Works
The CLI manages a two-way sync between local files and Buttondown’s media library:Pull: Download Images
When you run
buttondown pull, all images from your Buttondown media library are downloaded to media/ and a mapping is created in .buttondown-sync.json.Local Editing
You add or reference images in your emails using relative paths like
../media/image.png.Pulling Images
When you pull content, images are automatically downloaded:- Fetches all images from Buttondown’s
/imagesAPI endpoint - Downloads each image file to
media/ - Preserves original filenames
- Creates a sync state mapping
Image Download Process
Fromsrc/sync/images.ts:99:
Sync State Tracking
The.buttondown-sync.json file maintains the connection between local files and remote URLs:
.buttondown-sync.json
Adding Images to Emails
Reference images from themedia/ directory using relative paths:
emails/weekly-update.md
The path is relative to the
emails/ directory, so you use ../media/ to reference the media folder.Why Relative Paths?
Relative paths allow you to:- Preview emails locally with proper images
- Move your newsletter folder without breaking references
- Work offline
- Use standard Markdown tools
Pushing Images
When you push content, new images are automatically uploaded:- Scans all email files for image references
- Identifies images not yet in the sync state
- Uploads new images to Buttondown
- Updates the sync state with new mappings
- Converts relative paths to absolute URLs in email content
Image Upload Process
Fromsrc/sync/images.ts:24:
Automatic Path Conversion
The push command converts paths automatically:Supported Image Formats
The CLI supports these image formats:| Format | Extension | MIME Type |
|---|---|---|
| PNG | .png | image/png |
| JPEG | .jpg, .jpeg | image/jpeg |
| GIF | .gif | image/gif |
| WebP | .webp | image/webp |
| SVG | .svg | image/svg+xml |
src/sync/images.ts:15:
Working with Media
Adding a New Image
Organizing Images
You can organize images in subdirectories:Replacing an Image
To update an image:-
Replace the local file with the same filename:
-
Clear the sync state (optional) to force re-upload:
-
Push changes:
Image Reference Detection
The CLI uses regex to find image references in email content:- Standard Markdown images:
 - Relative paths:
../media/image.png - Subdirectory paths:
../media/screenshots/app.png
- Absolute URLs:
https://example.com/image.png - Protocol-relative URLs:
//example.com/image.png
src/sync/emails.ts:168:
Attachments
Attachments work differently from embedded images. They’re specified in frontmatter as URLs:Attachments must be publicly accessible URLs. The CLI doesn’t upload attachment files - only image files in the
media/ directory are automatically uploaded.Best Practices
Use descriptive filenames
Use descriptive filenames
Name images descriptively for easy reference:
Optimize images before adding
Optimize images before adding
Compress and resize images before adding to
media/ to keep email sizes manageable.- Use WebP for better compression
- Resize to appropriate dimensions
- Compress with tools like ImageOptim or TinyPNG
Include alt text
Include alt text
Always provide meaningful alt text for accessibility:
Keep media/ organized
Keep media/ organized
Use subdirectories to organize images by type or campaign:
Troubleshooting
”Image not found”
Make sure:- The image file exists in
media/ - The relative path is correct (use
../media/from emails) - The filename matches exactly (case-sensitive)
“Image upload failed”
Check that:- The file is a supported image format
- The file isn’t corrupted
- You have a valid API key with upload permissions
”Images not downloading”
If images don’t download during pull:- Check your internet connection
- Verify the remote images are accessible
- Ensure you have write permissions in the
media/directory
Next Steps
Manage Emails
Learn how to add images to your emails
Push Content
Upload your images to Buttondown