# Access, links and delivery
Source: https://sovaria.in/docs/storage-access

Who can upload, download and delete: bucket rules and their fields, public and signed URLs and how long links last, caching and bandwidth, what image transformations do today, and files in HIPAA projects.

## Create and manage buckets

Creating, changing, emptying and deleting a bucket is project administration: app users need the project's `admin` app role; console members and server keys are decided by your policies. supabase's names work in every SDK — `fileSizeLimit` takes bytes or a size like `'5MB'`; `allowedMimeTypes` takes patterns like `image/*`. `emptyBucket` deletes every file and keeps the bucket (1,000 files per round; the SDKs repeat until it is empty).

TypeScript:
```ts
const { error } = await sovaria.storage.createBucket('avatars', { public: true, fileSizeLimit: '2MB', allowedMimeTypes: ['image/*'] })
const { data: buckets } = await sovaria.storage.listBuckets()          // { data, error } with results: 'supabase'
await sovaria.storage.updateBucket('avatars', { fileSizeLimit: '5MB' })
await sovaria.storage.emptyBucket('scratch')
await sovaria.storage.deleteBucket('scratch')
```

Python:
```python
await sovaria.storage.create_bucket("avatars", {"public": True, "file_size_limit": "2MB", "allowed_mime_types": ["image/*"]})
buckets = await sovaria.storage.list_buckets()
await sovaria.storage.empty_bucket("scratch")
```

Swift:
```swift
try await sovaria.files.createBucket("avatars", isPublic: true, fileSizeLimit: "2MB", allowedMimeTypes: ["image/*"])
let buckets = try await sovaria.files.listBuckets()
try await sovaria.files.emptyBucket("scratch")
```

Kotlin:
```kotlin
sovaria.files.createBucket("avatars", isPublic = true, fileSizeLimit = "2MB", allowedMimeTypes = listOf("image/png", "image/webp"))
val buckets = sovaria.files.listBuckets()
sovaria.files.emptyBucket("scratch")
```

Dart:
```dart
await sovaria.files.createBucket('avatars', isPublic: true, fileSizeLimit: '2MB', allowedMimeTypes: ['image/*']);
final buckets = await sovaria.files.listBuckets();
await sovaria.files.emptyBucket('scratch');
```

## Bucket rules

Each bucket's **Policies** tab holds its rules (access policies named `[bucket:<name>] …`). Presets cover the usual cases; you can write your own with these fields ([Policy language (SPL)](https://sovaria.in/docs/policy-language)):

| Field | Value |
|---|---|
| `ctx.action` | `READ` (download), `LIST`, `WRITE` (upload, replace, move in), `DELETE` |
| `ctx.resource.name` | The bucket |
| `ctx.storage.path` | The file's path in the bucket |
| `ctx.storage.folder` | The path's first folder |
| `ctx.storage.in_own_folder` | `True` when that folder is the caller's user id |
| `ctx.org.*`, `ctx.app_metadata.*` | The caller's active app organization and admin-set metadata: one folder per tenant with `ctx.storage.folder == ctx.org.id` |
| `ctx.actor.*` | Who is calling ([How access is decided](https://sovaria.in/docs/access-model)) |

Access policy:
```bash
# Signed-in users manage their own folder; anyone signed in may read "shared/"
ALLOW IF ctx.resource.name == "documents" AND ctx.storage.in_own_folder == True
ALLOW IF ctx.resource.name == "documents" AND ctx.action IN ["READ", "LIST"] AND ctx.storage.folder == "shared" AND ctx.actor.is_anonymous == False
```

- With no rule for a bucket, only the public flag decides. Anyone may read a public bucket's files, but listing them needs a rule that allows `LIST`, or the bucket's own **Listable** switch (`public_list: true`). App users get nothing from a private bucket.
- Creating, deleting a bucket, making it public or changing its limits is administration: app users need the `admin` app role for it, whatever the file rules say.
- The Security advisor flags buckets without rules ([Security advisor](https://sovaria.in/docs/security-advisor)).

## Public URLs

Files in a **public** bucket have a permanent URL anyone can open, without a key:

JavaScript:
```js
const url = sovaria.storage.publicUrl('product-images', 'shoes/runner-01.webp')
// https://<project-ref>.sovarias.in/api/v1/store/public/<project-id>/product-images/shoes/runner-01.webp
```

Use public buckets only for files meant for everyone (product images, logos). Anyone who knows or guesses a path can download it. Listing a public bucket's files is off unless you turn it on (`public_list: true` when you create or update the bucket, or a storage rule that allows `LIST`).

## Signed URLs

A **signed URL** lets anyone holding it download (or upload) one file until it expires — without signing in. Create it on behalf of a user who is allowed to read the file; it carries no other access.

JavaScript:
```js
// Share a private file for 10 minutes
const { url, expires_at } = await sovaria.storage.signDownload('invoices', `${user.id}/2026-10.pdf`, 600)

// Let the browser upload directly (create this on your server; the browser tells you file.size)
const upload = await sovaria.storage.signUpload('uploads', `${user.id}/video.mp4`, 900, { sizeBytes })
await fetch(upload.url, { method: 'PUT', body: file })
```

cURL:
```bash
curl -s -X POST "$URL/api/v1/store/objects/invoices/$USER_ID/2026-10.pdf/sign-download" \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d '{"expires_in":600}'
```

supabase's two-step upload works the same in every SDK: `createSignedUploadUrl(path)` (on behalf of a user who may write there) gives a one-time URL and its `token`; `uploadToSignedUrl(path, token, file)` sends the file with no session. Download links take `download` to save the file (under a name you choose) and `transform` for a resized image ([Image transformations](https://sovaria.in/docs/storage-image-transforms)).

TypeScript:
```ts
const uploads = sovaria.storage.from('uploads')
const { data: link } = await uploads.createSignedUploadUrl(`${user.id}/video.mp4`, { size: file.size })
await uploads.uploadToSignedUrl(`${user.id}/video.mp4`, link.token, file)
const { data } = await uploads.createSignedUrl(`${user.id}/video.mp4`, 600, { download: 'my-video.mp4' })
```

Python:
```python
uploads = sovaria.storage.from_("uploads")
link = await uploads.create_signed_upload_url(f"{user_id}/video.mp4", {"size": size})
await uploads.upload_to_signed_url(f"{user_id}/video.mp4", link["token"], data, {"content-type": "video/mp4"})
```

Swift:
```swift
let uploads = sovaria.files.from("uploads")
let link = try await uploads.createSignedUploadURL(path: "\(userId)/video.mp4", size: data.count)
try await uploads.uploadToSignedURL(path: "\(userId)/video.mp4", token: link.token, data: data, contentType: "video/mp4")
```

Kotlin:
```kotlin
val uploads = sovaria.files.from("uploads")
val link = uploads.createSignedUploadUrl("$userId/video.mp4", size = bytes.size.toLong())
uploads.uploadToSignedUrl("$userId/video.mp4", link.token, bytes, "video/mp4")
```

Dart:
```dart
final uploads = sovaria.files.from('uploads');
final link = await uploads.createSignedUploadUrl('$userId/video.mp4', size: bytes.length);
await uploads.uploadToSignedUrl('$userId/video.mp4', link.token, bytes, contentType: 'video/mp4');
```

|  |  |
|---|---|
| Lifetime | `expires_in` seconds, from 1 second to 1 day (86,400). The SDKs default to 1 hour; the API defaults to 15 minutes when you leave it out. |
| Scope | One file, one method (download or upload). |
| Upload size | Pass `sizeBytes` (`size_bytes` over HTTP) with the file's exact size: the URL goes straight to storage and only accepts a file of that size, checked against the bucket's and your plan's file-size limit and your storage quota when you create it. Without a size, the URL uploads through Sovaria, which checks the limits as the bytes arrive. |
| Revoking | A signed URL can't be withdrawn before it expires — keep lifetimes short. Deleting or moving the file makes it stop working. |

## Caching and bandwidth

- Files are served with their stored content type; set `contentType` when uploading so browsers display them correctly.
- Downloads count toward the monthly bandwidth allowance ([Plan limits](https://sovaria.in/docs/plan-limits)); public files that can be cached by browsers and CDNs save bandwidth.
- Signed URLs are unique per signing, so caches can't share them — prefer public buckets for popular public files.

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Storage CDN tier | Standard | Standard | Standard | Premium | Premium |
| Monthly bandwidth | 2,147,483,648 | 21,474,836,480 | 64,424,509,440 | 429,496,729,600 | 5,497,558,138,880 |

## Image transformations

Resized and re-encoded images on the fly — thumbnails, avatars, WebP for slow networks — on paid plans: `getPublicUrl(path, { transform })`, `createSignedUrl(path, expiresIn, { transform })` and `download(path, { transform })`. Limits, caching and security: [Image transformations](https://sovaria.in/docs/storage-image-transforms).

## Files in HIPAA projects

In a project with HIPAA mode on, buckets can't be public (`PHI_PUBLIC_BUCKET_DISABLED`); share files with short-lived signed URLs instead ([HIPAA mode and PHI projects](https://sovaria.in/docs/hipaa)).

## Not supported

- File versioning or a trash: replaced and deleted files are gone.
- Per-file metadata beyond the content type, size and timestamps.
