Skip to content

Updated

Standard Uploads

Learn how to upload files to Supabase Storage.

Uploading#

The standard file upload method is ideal for small files that are not larger than 6MB.

You implement file uploads with the supabase-js SDK using the traditional multipart/form-data format. Here's an example of how to upload a file using the standard upload method:

import { } from '@supabase/supabase-js'
// Create Supabase client
const = ('your_project_url', 'your_supabase_api_key')
// Upload file using standard upload
async function () {
const { , } = await ..('bucket_name').('file_path', )
if () {
// Handle error
} else {
// Handle success
}
}

Overwriting files#

When uploading a file to a path that already exists, the default behavior is to return a 400 Asset Already Exists error. If you want to overwrite a file on a specific path you can set the upsert options to true or using the x-upsert header.

// Create Supabase client
const = ('your_project_url', 'your_supabase_api_key')
await ..('bucket_name').('file_path', , {
: true,
})

We do advise against overwriting files when possible, as our Content Delivery Network will take sometime to propagate the changes to all the edge nodes leading to stale content. Uploading a file to a new path is the recommended way to avoid propagation delays and stale content.

Content type#

By default, Storage will assume the content type of an asset from the file extension. If you want to specify the content type for your asset, pass the contentType option during upload.

// Create Supabase client
const = ('your_project_url', 'your_supabase_api_key')
await ..('bucket_name').('file_path', , {
: 'image/jpeg',
})

Concurrency#

When two or more clients upload a file to the same path, the first client to complete the upload will succeed and the other clients will receive a 400 Asset Already Exists error. If you provide the x-upsert header the last client to complete the upload will succeed instead.

Presigned uploads#

Standard uploads also support using signed upload tokens to create time-limited URLs that you can share with your users. Create the signed URL by invoking the createSignedUploadUrl method on the SDK, then pass the returned token to uploadToSignedUrl to complete the upload.

// Create a signed upload URL
const { data } = await supabase.storage.from('bucket_name').createSignedUploadUrl('file_path')
// Upload to the signed URL
const { error } = await supabase.storage
.from('bucket_name')
.uploadToSignedUrl('file_path', data.token, file)

Revoke signed URLs#

You can't revoke individual signed URLs. To revoke all signed URLs, rotate your project's URL signing key, and then revoke the previous key. For more information, see URL Signing Keys.