Quill image upload for paste and drag-drop
Capture image files from Quill's paste and drop events, upload them, and insert hosted CDN URLs with insertEmbed. Use the complete handler below or hand the ready-made prompt to your coding agent.
Claude CodeCursorWindsurfCopilot - 1Copy the prompt
The one big button below.
- 2Paste it into your agent
In your project — Claude Code, Cursor, etc.
- 3Drop in your key
Swap
pv_pub_REPLACE_MEfor a free key. Done.
Add image paste-and-host to my Quill editor using PixelVault.
Context — read this first and use only the documented API:
- Overview + API: https://pixelvault.dev/llms.txt
- PixelVault upload helper (from @pixelvault-dev/paste):
import { uploadImage } from "@pixelvault-dev/paste";
const { url } = await uploadImage(file, { publishableKey: "pv_pub_REPLACE_ME" });
// returns { id, url, mimeType, size }; throws PixelVaultPasteError on failure
Important: Quill is a contenteditable editor, not a <textarea>, so do NOT use the
paste-react/usePaste widget here — use uploadImage() directly.
Do this:
1. Install: npm install @pixelvault-dev/paste
2. On my Quill instance, listen for image files pasted or dropped into the editor:
add "paste" and "drop" listeners on quill.root, pull any image File out of
event.clipboardData / event.dataTransfer, and call event.preventDefault() so
Quill doesn't try to insert the raw image data itself.
3. For each image file: call uploadImage(file, { publishableKey }), and on success
insert it with Quill's documented embed API at the current selection:
const range = quill.getSelection(true);
quill.insertEmbed(range.index, "image", url, "user");
quill.setSelection(range.index + 1);
Show a fallback if the upload throws PixelVaultPasteError.
4. Use my publishable key where I wrote pv_pub_REPLACE_ME (I'll paste my own).
Rules:
- For the PixelVault part, use ONLY uploadImage(file, options) as documented above —
do NOT invent PixelVault endpoints, options, or other packages.
- Use Quill's own documented insertEmbed(index, "image", url) API for insertion.
- Don't block the editor on the upload; insert the image when the URL resolves. What the agent will do
- Install
@pixelvault-dev/paste(core) - Listen for pasted/dropped images on
quill.root, upload viauploadImage() - Insert with
quill.insertEmbed(i, 'image', url) - No backend changes — uploads go straight to PixelVault with your key
Grab your free key
The one thing the agent can't generate is your publishable key (pv_pub_…) — it's origin-scoped and upload-only, safe to ship in browser code. Create one, add your app's origin, and paste it in.
Free tier: 200 MB storage, 500 uploads/mo, 1 GB bandwidth. No card.
Complete Quill paste and drop handler
This helper handles every pasted or dropped image, uploads files in order, and inserts the hosted URLs at the current Quill selection. It returns a cleanup function so a component can remove both listeners when it unmounts.
import type Quill from "quill";
import {
PixelVaultPasteError,
imageFilesFromClipboard,
imageFilesFromDrop,
uploadImage,
} from "@pixelvault-dev/paste";
export function enablePixelVaultImageUploads(
quill: Quill,
publishableKey: string,
onError: (message: string) => void,
) {
async function uploadFiles(files: File[], insertAt: number) {
let index = insertAt;
for (const file of files) {
try {
const { url } = await uploadImage(file, { publishableKey });
quill.insertEmbed(index, "image", url, "user");
index += 1;
quill.setSelection(index, 0, "silent");
} catch (error) {
onError(
error instanceof PixelVaultPasteError
? error.message
: "Image upload failed. Try again.",
);
}
}
}
function onPaste(event: ClipboardEvent) {
const files = imageFilesFromClipboard(event);
if (files.length === 0) return;
event.preventDefault();
void uploadFiles(files, quill.getSelection(true).index);
}
function onDrop(event: DragEvent) {
const files = imageFilesFromDrop(event);
if (files.length === 0) return;
event.preventDefault();
void uploadFiles(files, quill.getSelection(true).index);
}
quill.root.addEventListener("paste", onPaste);
quill.root.addEventListener("drop", onDrop);
return () => {
quill.root.removeEventListener("paste", onPaste);
quill.root.removeEventListener("drop", onDrop);
};
}
Call enablePixelVaultImageUploads(quill, publishableKey, onError) after creating
the editor, then call its returned cleanup function when you dispose the Quill instance.
Connect onError to your existing toast or inline error state.
Why Quill needs a custom handler
Quill renders a contenteditable editor, not a <textarea>. The textarea
widget cannot attach to it, so the handler reads image files from the browser event, prevents
Quill from inserting raw image data, uploads each file with uploadImage(), and
inserts the returned URL with Quill's native insertEmbed() API.
No upload API route required
The browser uploads directly with a PixelVault publishable key. That key can only upload and only from origins you allow, so it is safe to use in client code. Keep the allowlist narrow and pass the key through your framework's browser-safe configuration.
Prefer your coding agent to make the change?
Copy the prompt above. It tells Claude Code, Cursor, Windsurf, or Copilot to find your Quill setup, add the same paste and drop handlers, and connect errors to the UI conventions already in your app. The paste-and-host docs cover every upload option, and the Lexical image upload guide covers Lexical's command-based equivalent.
FAQ
How do I add image upload to a Quill editor?
Read image files from Quill's paste and drop events, upload them with uploadImage(), then insert each hosted URL with quill.insertEmbed(). The complete handler above implements the flow and cleanup.
Why doesn't the textarea paste widget work with Quill?
Quill uses a contenteditable surface rather than a textarea. Use the lower-level upload helper and Quill's insertEmbed() API instead.
Do I need an upload backend for Quill image uploads?
No. uploadImage() uploads directly from the browser with an origin-scoped, upload-only publishable key.