Image
A dropzone for uploading a single image, with preview and upload status.
Click to upload or drag and drop
PNG, JPG, WEBP or GIF · up to 2 MB
Use it for covers, thumbnails and product shots. Dropping or choosing a new image replaces the current one, and the Replace and Remove buttons stay available after the upload completes.
Installation
Use the shadcn CLI to add the component to your project.
npx shadcn@latest add https://edgestore.dev/r/single-image-dropzone.jsonUsage
Install or copy the component from Installation before using this example.
'use client';
import { SingleImageDropzone } from '@/components/upload/single-image';
import {
UploaderProvider,
type UploadFn,
} from '@/components/upload/uploader-provider';
import { useEdgeStore } from '@/lib/edgestore';
import * as React from 'react';
export function SingleImageDropzoneUsage() {
const { edgestore } = useEdgeStore();
const uploadFn: UploadFn = React.useCallback(
async ({ file, onProgressChange, signal }) => {
const res = await edgestore.publicImages.upload({
file,
signal,
onProgressChange,
});
// you can run some server action or api here
// to add the necessary data to your database
console.log(res);
return res;
},
[edgestore],
);
return (
<UploaderProvider uploadFn={uploadFn} autoUpload>
<SingleImageDropzone
className="w-64"
aspectRatio="16 / 9"
maxSize={1024 * 1024 * 1} // 1 MB
/>
</UploaderProvider>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
aspectRatio | string | "1 / 1" | CSS aspect ratio of the dropzone. Set the width with className. |
maxSize | number | Maximum file size in bytes. | |
accept | Accept | PNG, JPG, WEBP, GIF | Accepted file types, in react-dropzone's format. |
typesLabel | string | "PNG, JPG, WEBP or GIF" | Human-readable list of accepted types, shown in the hint and in error messages. |
disabled | boolean | false | Disables the component. |
label | string | "image" | Name of the image, used in accessible labels. |