EdgeStore

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.json

Usage

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

PropTypeDefaultDescription
aspectRatiostring"1 / 1"CSS aspect ratio of the dropzone. Set the width with className.
maxSizenumberMaximum file size in bytes.
acceptAcceptPNG, JPG, WEBP, GIFAccepted file types, in react-dropzone's format.
typesLabelstring"PNG, JPG, WEBP or GIF"Human-readable list of accepted types, shown in the hint and in error messages.
disabledbooleanfalseDisables the component.
labelstring"image"Name of the image, used in accessible labels.

On this page