Upload a file
Uploads a file to an existing bucket.
Uploads a file to an existing bucket.
- Policy permissions required:
buckets
permissions: noneobjects
permissions:insert
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.
- 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`.
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.
final avatarFile = File('path/to/file');
final String path = await supabase.storage.from('avatars').upload(
'public/avatar1.png',
avatarFile,
fileOptions: const FileOptions(cacheControl: '3600', upsert: false),
);