Skip to content

Uploader

The Uploader component is used to upload files to a bucket.

This component must be a child of the SupabaseApp component to work.

Props

Prop nameTypeDescription
fileFileThe file to upload.
optionsobjectThe options to pass to the storage.upload method. Defaults to an empty object.

Slots

Prop nameTypeDescription
storageObjectThe storage client object from the Supabase SDK.
errorErrorAn error object if there was an error uploading the file, otherwise null.
uploadedFilestringThe name of the uploaded file if the upload was successful, otherwise null.

Usage

<script lang="ts">
import { BucketContext, Uploader } from 'supasvelte';
let file: File | null = null;
</script>
<BucketContext bucketName="test-bucket" path="public/">
<input type="file" on:change={(e) => (file = e?.currentTarget?.files?.[0] ?? null)} />
{#if file}
<Uploader {file} {options} let:uploadedFile let:error>
{#if error}
<div data-testid="upload-error">{error.message}</div>
{/if}
{#if uploadedFile}
<div data-testid="upload-filename">{uploadedFile}</div>
{/if}
</Uploader>
{/if}
</BucketContext>