Skip to Content

React Image Upload Component

Prepare image uploads with orientation-aware resizing, named variants, previews, optional cropping, hotspots, and an injected upload action.

Beta API maturity: Beta. This component is new and may evolve as its usage is validated.

ImageUpload combines the generic FileUpload selection and validation behavior with local image preparation. It shows a source preview, dimensions, sizes, and named variants. It does not choose a server, persist an asset, or send a request itself.

Prepare images locally

Select one or more images. The default processed file is resized without upscaling; optional named profiles create additional outputs. Browser orientation is applied and re-encoded outputs do not retain source metadata.

390 × 844

Without onUpload, files are prepared locally and remain in the component; no upload is attempted. With a handler and no editing controls, the handler is called after local processing. When crop or hotspot editing is enabled, preparation stays local until the user confirms with Upload image. Pass the supplied AbortSignal to the transport and report transfer progress from 0 to 100.

The original is not included by default. Set retainOriginal only when your application explicitly needs it: the retained file can still contain EXIF/GPS metadata. The processed result includes the default output's dimensions, format, and byte size; each named variant includes the same metadata. The UI shows the source and processed dimensions and their size difference.

Each item reports processing, uploading, ready, uploaded, failed, or cancelled through its visible status. Failed uploads can be retried without reprocessing a prepared result; cancelled or failed processing can be prepared again.

Crop and hotspot composition

enableCrop adds ImageCropper before processing. The crop is applied to the generated output; the returned normalized crop remains in the original source coordinate space. enableHotspots adds ImageHotspotEditor; its normalized focal point and hotspots use that same source coordinate space. The values are returned separately as crop and hotspots; the component does not infer a focal point, transform hotspot values, or persist the annotations.

Props

PropTypeDefaultDescription
acceptreadonly string[]["image/*"]Accepted MIME types.
multiplebooleanfalseAllow selecting multiple images.
maxFilesnumber—Maximum selected image count in multiple mode.
maxFileSizenumber—Maximum source size in bytes per image.
maxTotalSizenumber—Maximum combined selected size in bytes.
maxWidth, maxHeightnumber2048 eachMaximum default output dimensions; images are not upscaled.
qualitynumber0.85Encoding quality from 0 to 1.
format"image/jpeg" | "image/png" | "image/webp" | "image/avif"Source format or PNGRequested output format.
profiles{ name: string; maxWidth?: number; maxHeight?: number; format?: string; quality?: number }[]—Optional named responsive variants. Each profile needs a name and at least one maximum dimension.
retainOriginalbooleanfalseInclude the unmodified source File in the upload result.
enableCropbooleanfalseShow an optional normalized crop editor and require explicit upload confirmation.
cropAspectRationumber | "free""free"Aspect ratio for the crop editor.
enableHotspotsbooleanfalseShow focal-point and hotspot editing; requires explicit upload confirmation.
onUploadImageUploadHandler—Receives processed file, processing metadata, optional original and named variants, crop/hotspots, and an abortable progress context.
onChange(files: File[]) => void—Called when selection changes.
onProgress(file, progress) => void—Called for local processing and upload progress.
onCropChange(file, crop) => void—Receives normalized crop changes.
onHotspotsChange(file, value) => void—Receives normalized focal point and hotspot changes.

Other selection, validation, accessibility, and presentation props follow FileUploadProps. The public types ImageUploadProps, ImageUploadResult, ImageUploadContext, ImageUploadHandler, and ImageUploadStatus are exported from @puzzle-ui/ui.

The browser helpers are used only after a user selects an image. Importing the UI package remains SSR-safe; do not call browser processing helpers during server rendering.