Objects

Copy objects

The user has the ability to transfer items between buckets or within the same bucket. As of now, objects with a size of up to 5 GB can be duplicated through the utilization of the API.

When an individual initiates the duplication process of an object, they become the legal owner of the replicated object.

To copy an object within the same bucket, use the copy method.

await appizap.storage.from('avatars').copy('public/avatar1.png', 'private/avatar2.png')

To copy an object across buckets, use the copy method and specify the destination bucket.

await appizap.storage.from('avatars').copy('public/avatar1.png', 'private/avatar2.png', {
  destinationBucket: 'avatars2',
})

Move Objects

Objects can be transferred either between buckets or within the same bucket. The API only allows for the movement of objects that are up to 5GB in size.

When transferring an object, the individual responsible for the move will become the new owner of the object. After the transfer is completed, the initial object will cease to be in existence.

To move an object within the same bucket, you can use the move method.

const { data, error } = await appizap.storage
  .from('avatars')
  .move('public/avatar1.png', 'private/avatar2.png')

To move an object across buckets, use the move method and specify the destination bucket.

await appizap.storage.from('avatars').move('public/avatar1.png', 'private/avatar2.png', {
  destinationBucket: 'avatars2',
})

Permissions

In order for a user to manipulate objects by moving and copying them, it is required that the user possesses select permissions on the source object and insert permissions on the destination object. This requirement is exemplified by the following scenario:

create policy "User can select their own objects (in any buckets)"
on storage.objects
for select
to authenticated
using (
    owner_id = (select auth.uid())
);

create policy "User can upload in their own folders (in any buckets)"
on storage.objects
for insert
to authenticated
with check (
    (storage.folder(name))[1] = (select auth.uid())
);

Delete Objects

When you remove one or multiple objects from a bucket, they are permanently eliminated and cannot be recovered. It is possible to delete either a singular object or several objects simultaneously.

To delete one or more objects, use the remove method.

await appizap.storage.from('bucket').remove(['object-key-1', 'object-key-2'])

To delete an object, the user must have the delete permission on the object. For example:

create policy "User can delete their own objects"
on storage.objects
for delete
TO authenticated
USING (
    owner = (select auth.uid())
);

When removing objects, it is essential to utilize the Storage API instead of a SQL query. Deleting objects through a SQL query does not effectively eliminate the object from the bucket and can lead to the object becoming disconnected from its associated data.

Last updated