Replace an existing file
Replaces an existing file at the specified path with a new one.
- RLS policy permissions required:
buckets
table permissions: noneobjects
table permissions:update
andselect
- Refer to the Storage guide on how access control works
- For React Native, using either
Blob
,File
orFormData
does not work as intended. Update file usingArrayBuffer
from base64 file data instead, see example below.
Parameters
- pathREQUIREDstring
The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
- fileBodyREQUIREDobject
The body of the file to be stored in the bucket.
- fileOptionsOptionalFileOptionscacheControlOptionalstring
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.
contentTypeOptionalstringthe `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`.
duplexOptionalstringThe duplex option is a string parameter that enables or disables duplex streaming, allowing for both reading and writing data in the same stream. It can be passed as an option to the fetch() method.
upsertOptionalbooleanWhen 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.
const avatarFile = event.target.files[0]
const { data, error } = await supabase
.storage
.from('avatars')
.update('public/avatar1.png', avatarFile, {
cacheControl: '3600',
upsert: true
})