Guide
Image Upload
How to upload images in the editor.
Image Upload
Note on File Validation
The Image
extension does not provide built-in file validation. You must implement your own validateFn
to enforce file restrictions.
Basic Setup
Validation Function
validateFn
accepts a File
object as an argument and returns boolean
.
Validation Workflow
- User selects a file
validateFn
is called(if provided)- If
validateFn
returnstrue
, proceed touploadFn
- If
validateFn
returnsfalse
, upload is cancelled
Upload Function
uploadFn
accepts a File
object as an argument and returns a Promise<string>
that resolves to the URL of the uploaded image.
The uploadFn
handles the actual image upload process.
Image Upload Example
Best Practices
Security Considerations
- Always validate files on both client and server
- Implement file size and type restrictions
- Handle potential upload errors gracefully
Props
Image Upload Props
Props for the image upload plugin.
Prop | Type | Default | Required |
---|---|---|---|
uploadFn | function | No default value | true |
validateFn | function | No default value | No default value |
imageSourceType | "upload" | "url" | "both" | "both" | true |