Files
supabase/apps/docs/content/guides/storage/management/copy-move-objects.mdx
Tyler Hillery 79da6ab86f docs(storage): add object versioning and lifecycle policies guides (#51566)
## What

Adds docs for the Storage object versioning private alpha and bucket
lifecycle policies for noncurrent versions.

- New: `storage/buckets/object-versioning.mdx`,
`storage/buckets/lifecycle-policies.mdx`, plus nav entries
- Updated: copy/move, delete objects (versioned buckets and `aws s3
sync`), S3 compatibility (lifecycle rows, versioning note), schema
diagram (versioning columns), storage size (noncurrent versions count
toward storage size; current vs noncurrent query)
2026-11-25 13:53:55 -06:00

129 lines
4.4 KiB
Plaintext

---
id: 'storage-management'
title: 'Copy Objects'
description: 'Learn how to copy and move objects'
subtitle: 'Learn how to copy and move objects'
sidebar_label: 'Copy / Move Objects'
---
## Copy objects
You can copy objects between buckets or within the same bucket. Currently only objects up to 5 GB can be copied using the API.
When making a copy of an object, the owner of the new object will be the user who initiated the copy operation. For how Storage assigns owners, see [Storage ownership](/docs/guides/storage/security/ownership).
### Copying objects within the same bucket
To copy an object within the same bucket, use the `copy` method. Replace `YOUR_USER_ID` with the signed-in user's ID so the destination's first folder matches their JWT `sub` claim.
```javascript
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
await supabase.storage.from('avatars').copy('public/avatar1.png', 'YOUR_USER_ID/avatar2.png')
```
### Copying objects across buckets
To copy an object across buckets, use the `copy` method and specify the destination bucket.
```javascript
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
await supabase.storage.from('avatars').copy('public/avatar1.png', 'YOUR_USER_ID/avatar2.png', {
destinationBucket: 'avatars2',
})
```
## Move objects
You can move objects between buckets or within the same bucket. Currently only objects up to 5GB can be moved using the API.
When moving an object, the owner of the new object will be the user who initiated the move operation. Once the object is moved, the original object will no longer exist.
### Moving objects within the same bucket
To move an object within the same bucket, you can use the `move` method.
```javascript
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
const { data, error } = await supabase.storage
.from('avatars')
.move('public/avatar1.png', 'private/avatar2.png')
```
### Moving objects across buckets
To move an object across buckets, use the `move` method and specify the destination bucket.
```javascript
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
await supabase.storage.from('avatars').move('public/avatar1.png', 'private/avatar2.png', {
destinationBucket: 'avatars2',
})
```
## Copy or move a version
In a bucket with [object versioning](/docs/guides/storage/buckets/object-versioning) turned on, pass `sourceVersionId` to `copy` or `move` to use a specific version of the source object. The destination gets a new version ID.
```javascript
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
await supabase.storage.from('avatars').copy('public/avatar1.png', 'private/avatar1-backup.png', {
sourceVersionId: 'a1f2e3d4-5b6c-4d7e-8f9a-0b1c2d3e4f5a',
})
```
Moving a version copies it and then permanently deletes the source version. To restore a version to its own path, see [Restore a version](/docs/guides/storage/buckets/object-versioning#restore-a-version).
## Permissions
To **copy** objects, users need `select` permission on the source object and `insert` permission on the destination object. To copy over an existing object or delete marker, users also need `update` permission. With [object versioning](/docs/guides/storage/buckets/object-versioning) turned on, the replaced object is kept as a noncurrent version.
To **move** objects, users need `select` and `update` permissions on the object. If either bucket has versioning turned on, a move copies the object and then deletes the source version, so users need the copy permissions and `delete` permission on the source object.
For example:
```sql
create policy "User can select their own objects (in any buckets)"
on storage.objects
for select
to authenticated
using (
owner_id = (select auth.jwt()->>'sub')
);
create policy "User can insert in their own folders (in any buckets)"
on storage.objects
for insert
to authenticated
with check (
(storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);
create policy "User can update their own objects (in any buckets)"
on storage.objects
for update
to authenticated
using (
owner_id = (select auth.jwt()->>'sub')
);
```