from.upload()

Uploads a file to an existing bucket.

1final avatarFile = File('path/to/file');
2final String path = await supabase.storage.from('avatars').upload(
3      'public/avatar1.png',
4      avatarFile,
5      fileOptions: const FileOptions(cacheControl: '3600', upsert: false),
6    );

Parameters#

  • pathrequired
    string

    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.

  • fileBodyrequired
    string
    |
    ArrayBuffer
    |
    ArrayBufferView
    |
    Blob
    |
    Buffer
    |
    File
    |
    FormData
    |
    ReadableStream
    |
    ReadableStream
    |
    URLSearchParams

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

      Properties
    • URLSearchParamsrequired
      object

      No description provided.

    • stringrequired
      object

      No description provided.

    • ReadableStreamrequired
      object

      No description provided.

    • ReadableStreamrequired
      object

      No description provided.

    • FormDatarequired
      object

      No description provided.

    • Filerequired
      object

      No description provided.

    • Bufferrequired
      object

      No description provided.

    • Blobrequired
      object

      No description provided.

    • ArrayBufferViewrequired
      object

      No description provided.

    • ArrayBufferrequired
      object

      No description provided.

  • FileOptionsrequired
    object

    No description provided.

      Properties
    • cacheControloptional
      string

      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.

    • contentTypeoptional
      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.

    • upsertoptional
      boolean

      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#

  • Policy permissions required:
    • buckets permissions: none
    • objects permissions: insert

Examples#

Upload file#

1final avatarFile = File('path/to/file');
2final String path = await supabase.storage.from('avatars').upload(
3      'public/avatar1.png',
4      avatarFile,
5      fileOptions: const FileOptions(cacheControl: '3600', upsert: false),
6    );