Manage Files
This guide covers listing, inspecting, checking existence, copying, moving, and deleting files in Postgres-Native Cloud Storage.
Initialize
import cloudbase from '@cloudbase/js-sdk';
const app = cloudbase.init({ env: '<env-id>' });
const bucket = app.storage.from('user-files');
All path parameters are object names inside the bucket. Do not pass cloud:// fileIDs.
List files
Use list() to list objects by prefix with cursor pagination:
const { data, error } = await bucket.list('user-123', {
limit: 20,
withDelimiter: true,
sortBy: {
column: 'created_at',
order: 'desc',
},
});
if (error) {
throw error;
}
console.log(data.folders);
console.log(data.objects);
if (data.hasNext) {
const nextPage = await bucket.list('user-123', {
cursor: data.nextCursor,
});
console.log(nextPage.data?.objects);
}
list() requires a SELECT policy on storage.objects. For private user folders, restrict the first path segment to the current user ID.
CREATE POLICY user_files_select ON storage.objects
FOR SELECT TO authenticated
USING (
bucket_id = 'user-files'
AND (storage.foldername(name))[1] = auth.uid()
);