--- id: 'storage-management' title: 'Delete Objects' description: 'Learn about deleting objects' subtitle: 'Learn about deleting objects' sidebar_label: 'Delete Objects' --- Deleting an object removes it permanently. In a bucket with [object versioning](/docs/guides/storage/buckets/object-versioning) turned on, a delete adds a delete marker and keeps earlier versions so you can restore them. You can delete a single object or multiple objects at once. Deleting objects should always be done via the **Storage API** and NOT via a **SQL query**. Deleting objects via a SQL query will not remove the object from the bucket and will result in the object being orphaned. ## Delete objects To delete one or more objects, use the `remove` method. ```javascript import { createClient } from '@supabase/supabase-js' const supabase = createClient('your_project_url', 'your_supabase_api_key') // ---cut--- await supabase.storage.from('bucket').remove(['object-path-2', 'folder/avatar2.png']) ``` When deleting objects, there is a limit of 1000 objects at a time using the `remove` method. ## Emptying large buckets Deleting objects via the Supabase Dashboard or Storage API has a hard limit of 200,000 objects per bucket. If a bucket contains more than 200,000 objects, the empty bucket operation will fail. In a bucket with object versioning turned on, the limit counts every version and delete marker. In a bucket with object versioning turned on, `aws s3 sync --delete` adds a delete marker for each object and keeps every version, so storage usage stays the same. To delete the versions, use one of these options: - If the bucket is under the 200,000-object limit, call `emptyBucket`. - Set a [lifecycle policy](/docs/guides/storage/buckets/lifecycle-policies) to delete noncurrent versions on a schedule. The recommended approach for emptying large buckets is to use the AWS CLI with Supabase's S3 protocol support. You can delete all objects by using the `sync` command to sync your bucket with an empty local directory, which will safely delete all objects. 1. **Install the AWS CLI**: Follow the [AWS CLI installation guide](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) for your operating system. 2. **Set up S3 credentials in Supabase**: Generate your S3 access credentials by following the [Supabase S3 authentication guide](/docs/guides/storage/s3/authentication?queryGroups=language&language=credentials). 3. **Configure an AWS profile**: Run the following command and paste in the credentials you created in Supabase. The profile name `supabase-s3` can be anything you want, as long as it matches the value you use in the sync command. ```bash aws configure --profile supabase-s3 ``` 4. **Create an empty directory and sync it to your bucket**: ```bash # Create a local empty directory mkdir empty-dir # Sync the empty directory to your bucket with --delete enabled # This will delete all objects in the bucket aws s3 sync empty-dir/ s3://your-bucket-name --delete --profile supabase-s3 --endpoint-url https://.supabase.co/storage/v1/s3 --region ``` Replace `your-bucket-name`, ``, and `` with your actual values. This operation may take a while for large buckets, but it will not leave any orphaned objects behind. The `--profile` value must match the profile name you configured in Step 3. The correct endpoint URL and region can be found in your project's [Storage Settings](/dashboard/project/_/storage/settings). ## RLS To delete an object, the user must have the `delete` permission on the object. For example: ```sql create policy "User can delete their own objects" on storage.objects for delete TO authenticated USING ( owner_id = (select auth.jwt()->>'sub') ); ```