Skip to main content
Version: v2 RC

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, {
cacheControl: '3600',
upsert: false
})

Parameters

  • pathrequiredstring

    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.

  • fileBodyrequiredstring | ArrayBuffer | ArrayBufferView | Blob | Buffer | File | FormData | ReadableStream | ReadableStream | URLSearchParams

    The body of the file to be stored in the bucket.

      Properties
    • URLSearchParamsrequiredobject

      No description provided.

    • stringrequiredobject

      No description provided.

    • ReadableStreamrequiredobject

      No description provided.

    • ReadableStreamrequiredobject

      No description provided.

    • FormDatarequiredobject

      No description provided.

    • Filerequiredobject

      No description provided.

    • Bufferrequiredobject

      No description provided.

    • Blobrequiredobject

      No description provided.

    • ArrayBufferViewrequiredobject

      No description provided.

    • ArrayBufferrequiredobject

      No description provided.

  • FileOptionsrequiredobject

    No description provided.

      Properties
    • cacheControloptionalstring

      The number of seconds the asset is cached in the browser and in the Supabase CDN. This is set in the Cache-Control: max-age=<seconds> header. Defaults to 3600 seconds.

    • contentTypeoptionalstring

      the Content-Type header value. Should be specified if using a fileBody that is neither Blob nor File nor FormData, otherwise will default to text/plain;charset=UTF-8.

    • upsertoptionalboolean

      When upsert is set to true, the file is overwritten if it exists. When set to false, an error is thrown if the object already exists. Defaults to false.

Notes

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: insert
  • Refer to the Storage guide on how access control works
  • For React Native, using either Blob, File or FormData does not work as intended. Upload file using ArrayBuffer from base64 file data instead, see example below.

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'
})