Skip to main content
Version: 1.0.0

Image Upload

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

Dragble storage (default)

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

<DragbleEditor ref={editorRef} editorKey="db_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 { DragbleEditor, DragbleEditorRef } from "dragble-react-editor";

function CustomUploadEditor() {
const editorRef = useRef<DragbleEditorRef>(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 (
<DragbleEditor
ref={editorRef}
editorKey="db_your_key"
editorMode="email"
onUpload={handleUpload}
/>
);
}

:::warning 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 dragble.uploadImage(file);

:::tip Accepted formats The editor accepts JPEG, PNG, GIF, WebP, and SVG files by default. Maximum file size is determined by your Dragble 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