Overview
The File plugin provides a complete solution for uploading and attaching files to your content. It supports file uploads, displays file information (name, size, type), and provides download functionality with automatic file type detection and icons.Installation
Basic Usage
Pass the plugin tocreateYooptaEditor; do not pass plugins to <YooptaEditor>.
Features
- File Upload: Upload files from device
- Custom Upload Functions: Direct uploads to S3, Firebase, Cloudinary, etc.
- File Type Detection: Automatic detection of file types (PDF, Document, Spreadsheet, etc.)
- File Icons: Different icons for different file types
- File Size Display: Human-readable file size formatting
- Download Support: One-click download functionality
- File Deletion: Optional deletion handling with custom functions
- Accept Filter: Restrict allowed file types
Configuration
The File plugin supports two approaches for upload and delete operations:- Endpoint-based: Configure an API endpoint and the plugin handles the request
- Custom function: Provide your own async function for complete control
Endpoint-based Upload (Backend API)
Custom Upload Function (Direct to Cloud)
For direct uploads to third-party services like AWS S3, Firebase Storage, or Cloudinary:The
delete option is optional. If not provided, deleting a file block will only remove it from the editor without calling any storage deletion logic.Options
upload (required)
Can be either an object (endpoint-based) or a function (custom upload):- Endpoint Object
- Custom Function
delete (optional)
Can be either an object (endpoint-based) or a function (custom delete):- Endpoint Object
- Custom Function
Accepted file types. Can be file extensions (e.g., “.pdf,.doc”) or MIME types (e.g., “application/pdf”).
Maximum file size in bytes
Global error handler for upload/delete operations
Element Props
Unique identifier for the file (from your storage)
URL of the uploaded file
File name (without extension)
File size in bytes
File extension (e.g., “pdf”, “docx”)
Commands
Utility Functions
File Type Detection
File Size Formatting
Supported File Types
The plugin automatically detects and displays appropriate icons for these file types:| Type | Extensions | Icon |
|---|---|---|
.pdf | 📄 | |
| Document | .doc, .docx, .odt, .rtf, .pages | 📝 |
| Spreadsheet | .xls, .xlsx, .csv, .ods, .numbers | 📊 |
| Presentation | .ppt, .pptx, .odp, .key | 📽️ |
| Image | .jpg, .png, .gif, .webp, .svg | 🖼️ |
| Video | .mp4, .webm, .mov, .avi | 🎬 |
| Audio | .mp3, .wav, .ogg, .flac | 🎵 |
| Archive | .zip, .rar, .7z, .tar, .gz | 📦 |
| Code | .js, .ts, .py, .html, .css, .json | 💻 |
| Text | .txt, .md, .log | 📃 |
Custom Rendering
Shadcn Theme Integration
When using@yoopta/themes-shadcn, the File plugin gets a beautiful UI automatically:
- Upload placeholder with file picker
- File card with type-specific icons and colors
- Inline toolbar with actions (download, copy URL, replace, delete)
- Upload progress indicator
- Hover states and animations
Parsers
HTML Deserialization
The plugin automatically deserializes<a> tags with download attribute:
HTML Serialization
Markdown Serialization
Hooks
useFileUpload
useFileDelete
Use Cases
Document Sharing
Attach PDFs, Word docs, and spreadsheets
Resource Downloads
Provide downloadable resources
File Libraries
Build document libraries and archives
Asset Management
Manage project assets and files
Best Practices
Set File Size Limits
Set File Size Limits
Configure
maxFileSize to prevent oversized uploads:Filter Allowed File Types
Filter Allowed File Types
Use
accept to restrict file types:Handle Upload Errors
Handle Upload Errors
Provide user feedback on errors:
Store File Metadata
Store File Metadata
Always return complete metadata from upload:
Troubleshooting
Error: Upload options are not configured
Error: Upload options are not configured
This error occurs when you haven’t configured the
upload option.Solution: Add an upload configuration to your File plugin:Error: Missing 'endpoint' in upload options
Error: Missing 'endpoint' in upload options
This error occurs when using endpoint-based configuration without providing the
endpoint URL.Solution: Make sure to include the endpoint property:File type not detected correctly
File type not detected correctly
Ensure the filename includes the correct extension. The plugin uses file extension for type detection.Solution: Return the format in your upload response:
Download not working
Download not working
Make sure the
src URL is accessible and has proper CORS headers for download.Solution: Ensure your storage returns files with Content-Disposition: attachment header or use the download attribute on links.Related Plugins
- Image Plugin - For image content
- Video Plugin - For video content
- Embed Plugin - For embedded content

