Creating Buckets
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
You can create a bucket using the Supabase Dashboard. Since storage is interoperable with your Postgres database, you can also use SQL or our client libraries. Here we create a bucket called "avatars":
1import { createClient } from '@supabase/supabase-js'2const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_KEY!)34// ---cut---5// Use the JS library to create a bucket.67const { data, error } = await supabase.storage.createBucket('avatars', {8 public: true, // default: false9})Restricting uploads#
When creating a bucket you can add additional configurations to restrict the type or size of files you want this bucket to contain.
For example, imagine you want to allow your users to upload only images to the avatars bucket and the size must not be greater than 1MB. You can achieve the following by providing allowedMimeTypes and maxFileSize:
1import { createClient } from '@supabase/supabase-js'2const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_KEY!)34// ---cut---5// Use the JS library to create a bucket.67const { data, error } = await supabase.storage.createBucket('avatars', {8 public: true,9 allowedMimeTypes: ['image/*'],10 fileSizeLimit: '1MB',11})If an upload request doesn't meet the above restrictions it will be rejected. See File Limits for more information.