Skip to main content

Image Upload

Configure how images are uploaded and stored when users drag, paste, or browse for images in the editor.

Pexelize storage (default)

Images are uploaded to Pexelize CDN automatically with no configuration required. The editor returns a hosted URL for each upload:

<PexelizeEditor
ref={editorRef}
editorKey="pk_your_key"
editorMode="email"
/>

Custom upload handler

Handle uploads yourself by providing an onUpload callback that receives the file and returns a URL:

import { useRef } from 'react';
import { PexelizeEditor, PexelizeEditorRef } from '@pexelize/react-editor';

function CustomUploadEditor() {
const editorRef = useRef<PexelizeEditorRef>(null);

const handleUpload = async (file: File): Promise<{ url: string }> => {
const formData = new FormData();
formData.append('image', file);

const res = await fetch('/api/images/upload', {
method: 'POST',
body: formData,
});
const { url } = await res.json();
return { url };
};

return (
<PexelizeEditor
ref={editorRef}
editorKey="pk_your_key"
editorMode="email"
onUpload={handleUpload}
/>
);
}
Return format

The onUpload callback must return a promise resolving to { url: string }. If the upload fails, throw an error and the editor will display a failure message to the user.

Programmatic upload

Trigger an upload from outside the editor:

const { url } = await pexelize.uploadImage(file);
Accepted formats

The editor accepts JPEG, PNG, GIF, WebP, and SVG files by default. Maximum file size is determined by your Pexelize plan or your custom upload handler.

Method reference

MethodReturnsDescription
uploadImage(file)Promise<{ url: string }>Programmatically upload an image
CallbackParametersDescription
onUpload(file: File) => Promise<{ url: string }>Custom upload handler replacing default storage

Next steps