> ## Documentation Index
> Fetch the complete documentation index at: https://corebase-docs-new.trivyaa.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Storage

> Upload and manage files.

CoreBase makes file uploads easy. You can upload files directly from the browser to your storage buckets.

## Buckets

Files live inside buckets — create one before uploading to it.

```typescript theme={null}
await corebase.storage.createBucket({
  name: 'avatars',
  public: true,
  allowedMimeTypes: ['image/png', 'image/jpeg'],
  fileSizeLimit: 5 * 1024 * 1024, // 5MB
});

const { data: buckets } = await corebase.storage.listBuckets();
const { data } = await corebase.storage.getBucket('avatars'); // bucket + its files
```

<Note>
  A bucket must be empty before you can delete it — use `emptyBucket()` first, or
  `deleteBucket()` will fail.
</Note>

## Upload a File

<Steps>
  <Step title="Get the file from an input">
    Use a standard HTML file input to select a file from the user's device.

    ```typescript theme={null}
    // Example: <input type="file" id="fileInput" />
    const fileInput = document.getElementById('fileInput') as HTMLInputElement;
    const file = fileInput.files?.[0];
    ```
  </Step>

  <Step title="Upload the file to a bucket">
    Call the upload method with the selected file and the bucket name.

    ```typescript theme={null}
    if (file) {
      const { data, error } = await corebase.storage.upload(file, 'avatars');

      if (error) {
        console.error('Upload failed:', error);
      } else {
        console.log('Success! File uploaded.');
        console.log('File Key:', data.key);
        console.log('File URL:', data.url);
      }
    }
    ```
  </Step>
</Steps>

## List & Delete Files

```typescript theme={null}
const { data: files } = await corebase.storage.listFiles({ bucket: 'avatars' });

// Download the raw bytes (e.g. to re-upload elsewhere, or process server-side)
const { data: blob } = await corebase.storage.downloadFile(files.files[0].id);

await corebase.storage.deleteFile(files.files[0].id);
```

<Tip>
  For displaying a file (e.g. in an `<img>` tag), use the `url` returned from `upload()`
  or found on each file record — `downloadFile()` is for when you need the raw bytes in code.
</Tip>
