ImageUpload

An image upload lets the user choose or drop an image and shows the result.

Default

Click the area, press Enter on it, or drop an image on it. While onUpload runs a spinner shows. This example makes a local preview instead of uploading.

Click or drop an image to upload
svelte
svelte
<ImageUpload
	bind:value={uploaded}
	onUpload={async (file) => {
		// Send the file to your server here and return the URL of the image
		return URL.createObjectURL(file);
	}} />

With an image

With a value the image shows with a delete button. Removing it empties value and calls onRemove.

svelte
svelte
<ImageUpload
	bind:value={existing}
	onUpload={upload}
	onRemove={() => console.log("Image removed")} />

Disabled

A disabled upload can't be used.

Click or drop an image to upload
svelte
svelte
<ImageUpload disabled onUpload={upload} />

Maximum size

This upload accepts files up to 100 KB. Choose a larger image to see the refusal.

Click or drop an image to upload
svelte
svelte
<ImageUpload bind:value={small} maxSizeBytes={100 * 1024} onUpload={upload} />