# EdgeStore Docs: Upload Button
URL: https://edgestore.dev/docs/components/upload-button
Source: https://raw.githubusercontent.com/edgestorejs/edgestore/refs/heads/main/docs/content/docs/components/upload-button.mdx
import { DemoBlock } from '@/components/demo-block';
import { LimitedCode } from '@/components/ui/limited-code';
import {
OpenTabs,
OpenTabsContent,
OpenTabsList,
OpenTabsTrigger,
} from '@/components/ui/open-tabs';
import UploadButtonBlock from '@/components/upload/blocks/upload-button-block';
import { Step, Steps } from 'fumadocs-ui/components/steps';
It takes the same props as the shadcn/ui `Button`. Several buttons can feed the same `UploaderProvider`, so you can pair them with a `FileList` or build your own list with `useUploader`.
## Installation
CLI
Manual
Use the shadcn CLI to add the component to your project.
npm
pnpm
yarn
bun
```bash
npx shadcn@latest add https://edgestore.dev/r/upload-button.json
```
```bash
pnpm dlx shadcn@latest add https://edgestore.dev/r/upload-button.json
```
```bash
yarn dlx shadcn@latest add https://edgestore.dev/r/upload-button.json
```
```bash
bun x shadcn@latest add https://edgestore.dev/r/upload-button.json
```
### Setup for manual installation
First you will need to follow the [manual install setup](./manual-install) guide.
### Install required components
* [uploader-provider](./uploader-provider)
* [dropzone](./dropzone)
* [shadcn/ui button](https://ui.shadcn.com/docs/components/button)
### Copy this component
````tsx title="components/upload/upload-button.tsx"
'use client';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import * as React from 'react';
import { type Accept } from 'react-dropzone';
import { dropzoneState, useUploadDropzone } from './dropzone';
/**
* Props for the UploadButton component.
*/
export type UploadButtonProps = Omit<
React.ComponentProps,
'onClick' | 'type' | 'className'
> & {
className?: string;
/**
* Accepted file types.
*/
accept?: Accept;
/**
* Human-readable list of accepted types, used in messages.
*/
typesLabel?: string;
/**
* Maximum file size in bytes.
*/
maxSize?: number;
/**
* Maximum number of files allowed in total.
*/
maxFiles?: number;
/**
* Whether more than one file can be picked at once.
* @default true
*/
multiple?: boolean;
/**
* Called with messages about files that were not added
* (wrong type, too large, over the limit).
*/
onRejected?: (messages: string[]) => void;
};
/**
* A button that opens the file dialog and also accepts files dropped onto it.
* Several buttons can feed the same `UploaderProvider`.
*
* @example
* ```tsx
*
* Upload files
*
* ```
*/
export function UploadButton({
accept,
typesLabel,
maxSize,
maxFiles,
multiple = true,
onRejected,
disabled,
className,
children,
...props
}: UploadButtonProps) {
const { getRootProps, getInputProps, isDragActive, isDragReject, isFull } =
useUploadDropzone({
accept,
typesLabel,
maxSize,
maxFiles,
multiple,
disabled,
onRejected,
// A
## Usage
Install or copy the component from [Installation](#installation) before using this example.
```tsx
'use client';
import { UploadErrors } from '@/components/upload/dropzone';
import { FileList } from '@/components/upload/multi-file';
import { UploadButton } from '@/components/upload/upload-button';
import {
UploaderProvider,
type UploadFn,
} from '@/components/upload/uploader-provider';
import { useEdgeStore } from '@/lib/edgestore';
import { UploadIcon } from 'lucide-react';
import * as React from 'react';
export function UploadButtonUsage() {
const [errors, setErrors] = React.useState([]);
const { edgestore } = useEdgeStore();
const uploadFn: UploadFn = React.useCallback(
async ({ file, onProgressChange, signal }) => {
const res = await edgestore.publicFiles.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 (
Upload files
setErrors([])} />
);
}
```
## Props
| Prop | Type | Default | Description |
| ---------------------- | ------------------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| `maxFiles` | `number` | | Maximum number of files in total. |
| `multiple` | `boolean` | `true` | Whether more than one file can be picked at once. |
| `onRejected` | `(messages: string[]) => void` | | Called with messages about files that were not added. |
| `maxSize` | `number` | | Maximum file size in bytes. |
| `accept` | `Accept` | all types | Accepted file types, in [react-dropzone's format](https://react-dropzone.js.org/#section-accepting-specific-file-types). |
| `typesLabel` | `string` | | Human-readable list of accepted types, shown in the hint and in error messages. |
| `disabled` | `boolean` | `false` | Disables the component. |
| `variant`, `size`, ... | | | Any other [Button](https://ui.shadcn.com/docs/components/button) prop. |