Skip to main content

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 to createYooptaEditor; do not pass plugins to <YooptaEditor>.
Required ConfigurationYou must configure the upload option. Without this option, you’ll see an error when trying to use the File plugin.
See the Configuration section below for detailed examples.

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:
  1. Endpoint-based: Configure an API endpoint and the plugin handles the request
  2. 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):
object

delete (optional)

Can be either an object (endpoint-based) or a function (custom delete):
object
string
Accepted file types. Can be file extensions (e.g., “.pdf,.doc”) or MIME types (e.g., “application/pdf”).
number
Maximum file size in bytes
function
Global error handler for upload/delete operations

Element Props

string | null
Unique identifier for the file (from your storage)
string | null
URL of the uploaded file
string | null
File name (without extension)
number | null
File size in bytes
string | null
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:

Custom Rendering

Shadcn Theme Integration

When using @yoopta/themes-shadcn, the File plugin gets a beautiful UI automatically:
The Shadcn theme provides:
  • 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

Configure maxFileSize to prevent oversized uploads:
Use accept to restrict file types:
Provide user feedback on errors:
Always return complete metadata from upload:

Troubleshooting

This error occurs when you haven’t configured the upload option.Solution: Add an upload configuration to your File plugin:
This error occurs when using endpoint-based configuration without providing the endpoint URL.Solution: Make sure to include the endpoint property:
Ensure the filename includes the correct extension. The plugin uses file extension for type detection.Solution: Return the format in your upload response:
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.