JavaScript: update
Replaces an existing file at the specified path with a new one.
Parameters
path
(Required)The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
fileBody
(Required)The body of the file to be stored in the bucket.
fileOptions
(Optional)Optional file upload options including cacheControl, contentType, contentEncoding, and metadata. **Note:** The `upsert` option has no effect here. `update()` always replaces the file at the given path, so the `x-upsert` header is not sent. To control upsert behavior, use `upload()` instead.
Examples
Update file
const avatarFile = event.target.files[0]
const { data, error } = await supabase
.storage
.from('avatars')
.update('public/avatar1.png', avatarFile, {
cacheControl: '3600'
})
Update file using `ArrayBuffer` from base64 file data
import {decode} from 'base64-arraybuffer'
const { data, error } = await supabase
.storage
.from('avatars')
.update('public/avatar1.png', decode('base64FileData'), {
contentType: 'image/png'
})
