from.upload()

Uploads a file to an existing bucket.

const avatarFile = event.target.files[0]
const { data, error } = await supabase
.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile)

Parameters

  • pathrequiredstring

    The relative file path including the bucket ID. Should be of the format bucket/folder/subfolder/filename.png. The bucket must already exist before attempting to upload.

  • filerequiredFile

    The File object to be stored in the bucket.

  • fileOptionsoptionalFileOptions

    HTTP headers. For example cacheControl

Notes

  • Policy permissions required:
    • buckets permissions: none
    • objects permissions: insert

Examples

Upload file

const avatarFile = event.target.files[0]
const { data, error } = await supabase
.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile)