Skip to content

Quickstart: Sypnia Cloud

Create a bucket, write a rule, upload a file from your app and show a resized image.

Applies to Cloud
View as Markdown
On this page
  1. Create a bucket
  2. Allow each user to write their own folder
  3. Upload from your app
  4. Show it resized

At the end, your app uploads a profile photo for the signed-in user and shows it at 256 px.

  1. Create a bucket

    Terminal
    npx @sypnia/files login
    npx @sypnia/files buckets create avatars --public --max-size 5MB --types image/jpeg,image/png,image/webp
    You should see
    Bucket avatars created (public).
  2. Allow each user to write their own folder

    SQL
    create policy "own avatar" on sypnia_files.objects for insert to authenticated
      with check (bucket_id = 'avatars' and (sypnia_files.foldername(name))[1] = auth.uid()::text);

    Run it in the SQL editor of the console, or with npx @sypnia/files policies apply policies.sql.

  3. Upload from your app

    TypeScript
    import { createFiles } from '@sypnia/files/client';
    
    const files = createFiles('https://<ref>.files.sypnia.com', { session: sypnia.auth }); // sypnia: your @sypnia/data client
    await files.bucket('avatars').upload(`${user.id}/photo.jpg`, file, { upsert: true });
  4. Show it resized

    TypeScript
    const src = files.bucket('avatars').url(`${user.id}/photo.jpg`, { width: 256, height: 256, resize: 'cover', format: 'webp' });
    You should see
    An address on <ref>.files.sypnia.app that returns a 256 × 256 WebP.
  1. Create a bucket
  2. Allow each user to write their own folder
  3. Upload from your app
  4. Show it resized

    Search pages, sections and terms