Upload a file
Uploads a file to an existing bucket.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:insert
- For React Native, using either
Blob
,File
orFormData
does not work as intended. Upload file usingArrayBuffer
from base64 file data instead, see example below.
Parameters
path
REQUIRED
stringThe relative file path. Should be of the format folder/subfolder/filename.png
. The bucket must already exist before attempting to upload.
fileBody
REQUIRED
objectThe body of the file to be stored in the bucket.
fileOptions
Optional
FileOptionsHTTP headers.
cacheControl
: string, the Cache-Control: max-age=<seconds>
seconds value.
contentType
: string, 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
.
upsert
: boolean, whether to perform an upsert.
cacheControl
Optional
undefined | stringcontentType
Optional
undefined | stringupsert
Optional
undefined | false | true
const avatarFile = event.target.files[0]
const { data, error } = await supabase
.storage
.from('avatars')
.upload('public/avatar1.png', avatarFile, {
cacheControl: '3600',
upsert: false
})