JavaScript: Upload a file | Supabase Docs (original) (raw)

Uploads a file to an existing bucket.

Parameters

(Required)
The file path, including the file name. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.

(Required)
The body of the file to be stored in the bucket.

(Optional)

Examples

Upload file

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

Upload file using `ArrayBuffer` from base64 file data

import { decode } from 'base64-arraybuffer'

const { data, error } = await supabase
  .storage
  .from('avatars')
  .upload('public/avatar1.png', decode('base64FileData'), {
    contentType: 'image/png'
  })