# Storage

Source: https://docs.sociaro.com/storage/

Choose where the files of your generations are kept: on Sociaro storage, not at all on the gateway, or in your own bucket. The setting is per organisation and applies to job outputs, to files you upload with the [Files API](https://docs.sociaro.com/files/index.md), and to the links in [webhooks](https://docs.sociaro.com/jobs/webhooks/index.md).

## Who can change it

Only the organisation owner changes storage, in the customer console under **Storage**. Other members can open the page and see the current setting, without credentials. Nobody else can save, test or reset it.

## The three options

| Option | Where results are kept | Links in `outputs[].url` |
| --- | --- | --- |
| Sociaro storage (default) | On our storage, until you delete them. | Permanent links on `cdn.sociaro.com`. |
| Do not store on gateway | Nowhere. | Temporary links. |
| Your own bucket | In your bucket. | Presigned links or your public URL. |

### Sociaro storage

The default, shown as **Sociaro CDN** in the console. Nothing to set up. Outputs and uploads stay on `cdn.sociaro.com` links until you delete them with `DELETE /v2/files/{id}`. Files are kept for up to ten years, then removed.

### Do not store on gateway

New results are not saved on the gateway. A result is delivered through a temporary link:

- For `/v2` results the link works for up to its link lifetime, which is at least one hour, and only while the provider keeps the result. `expires_at` on the output is when the link is meant to stop working. The provider can remove the result sooner, so it is not a guaranteed availability deadline.
- An expired link cannot be downloaded again. Download the file while the link is valid and keep your own copy.
- `POST /v2/files` is refused with `403` and `storage_disabled`. To use your own input files, send public HTTPS URLs, or choose another option.
- Files saved on Sociaro storage before you switched stay until you delete them (for up to ten years), and can still be listed, read and deleted. Files in a former bucket are covered under [Switching](https://docs.sociaro.com/storage/#switching).

```json
{"error": {"type": "forbidden", "code": "storage_disabled",
           "message": "persistent file storage is disabled for this organisation; enable your own bucket or Sociaro storage in the console", "provider_message": null}}
```

### Your own bucket

Results are written to a bucket you own. Links in `outputs[].url` are presigned, proxied through our API, or on your public address. Supported: S3-compatible storage (AWS S3, Cloudflare R2, MinIO and similar) and Google Cloud Storage. To create the bucket and its key, see [Set up your bucket](https://docs.sociaro.com/storage/#set-up-your-bucket).

| Field | Meaning |
| --- | --- |
| Provider | AWS S3, Cloudflare R2, MinIO, other S3-compatible, or Google Cloud Storage. |
| Bucket | The bucket name. |
| Prefix | Optional folder. Objects are written under `<prefix>/`. |
| Endpoint and region | For S3-compatible storage. The endpoint is required for R2, MinIO and other S3-compatible services, optional for AWS S3. Public HTTPS addresses only. |
| Path-style addressing | Optional switch for S3-compatible storage. |
| Access key ID and secret | For S3-compatible storage. |
| Service account key | For Google Cloud Storage, a JSON key file. |
| Delivery | How links are built, see below. |

**Delivery.**

- **Presigned links.** The bucket stays private. Each link is signed and works for the lifetime you set, from 1 minute to 7 days (default 1 hour). When a link has expired, fetch the job (`GET /v2/jobs/{id}`) or the file (`GET /v2/files/{id}`) again for a fresh link. `expires_at` on the output is the retention of the file, not the lifetime of the link.
- **Private gateway proxy.** The bucket stays private and its address is never shown. `outputs[].url` is an `api.sociaro.com` link that streams the file from your bucket and needs your API key, like a `/v1/media` link. Send the key only to the API host.
- **Your public URL.** Set a public HTTPS address in front of the bucket, for example a CDN domain. Links are `<your address>/<object key>` and do not expire.

Links always follow your current settings. After you change the bucket or the delivery, new results and the links given from then on follow the new setting. Presigned links you already received keep working until they expire, but only while the bucket, the object, the signing key and its read permission still exist. Revoking that key, removing its read permission or deleting the object ends them sooner. For files in a former bucket see [Switching](https://docs.sociaro.com/storage/#switching).

**Test before saving.** **Test connection** writes a small test object, reads it and deletes it, and tells you which step failed. Saving runs the same test, and nothing is saved if it fails. You can also re-test a saved setting at any time.

**Credentials are never shown again.** After saving, the console shows only a short hint (the last 4 characters of the key ID, or the service account email). To change other fields, leave the credentials as they are. To change the credentials, replace them.

## Set up your bucket

Create the bucket and a key at your provider, then open **Storage** in the console, choose **Your own bucket**, enter them, select **Test connection** and save. Give the key only what the [checklist](https://docs.sociaro.com/storage/#checklist-for-your-bucket) lists.

### Cloudflare R2

1. Create a bucket in the Cloudflare dashboard under **R2** ([Create new buckets](https://developers.cloudflare.com/r2/buckets/create-buckets/)).
2. Create an R2 API token with the **Object Read & Write** permission and limit it to that bucket. Copy the **Access Key ID** and the **Secret Access Key** right away: the secret is shown only once ([R2 API tokens](https://developers.cloudflare.com/r2/api/tokens/)).
3. In the console choose **Cloudflare R2**. The endpoint is `https://<ACCOUNT_ID>.r2.cloudflarestorage.com` with your Cloudflare account ID, and the region is `auto` ([R2 S3 API](https://developers.cloudflare.com/r2/api/s3/api/)).

### Amazon S3

1. Create a general purpose bucket and note its Region ([Creating a bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)).
2. Create an IAM user for Sociaro ([Create an IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html)) and attach the policy below ([policy examples](https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-policies-s3.html)).
3. Create an access key for that user and copy the access key ID and the secret access key ([Manage access keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)).
4. In the console choose **Amazon S3**, enter the bucket's Region and leave the endpoint empty.
5. Optional: add a lifecycle rule that aborts incomplete multipart uploads after 1 day ([Lifecycle rule for incomplete multipart uploads](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html)).

The policy for step 2. Without a prefix, the resource is `arn:aws:s3:::<bucket>/*`.

```json
{"Version": "2012-10-17",
 "Statement": [{"Effect": "Allow",
                "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject", "s3:AbortMultipartUpload"],
                "Resource": "arn:aws:s3:::<bucket>/<prefix>/*"}]}
```

### Google Cloud Storage

1. Create a bucket ([Create a bucket](https://docs.cloud.google.com/storage/docs/creating-buckets)).
2. Create a service account ([Create service accounts](https://docs.cloud.google.com/iam/docs/service-accounts-create)).
3. On the bucket, grant the service account a role with `storage.objects.create`, `storage.objects.get` and `storage.objects.delete`, for example **Storage Object User** ([Add a principal to a bucket-level policy](https://docs.cloud.google.com/storage/docs/access-control/using-iam-permissions), [IAM roles for Cloud Storage](https://docs.cloud.google.com/storage/docs/access-control/iam-roles)).
4. Create a JSON key for the service account and download it ([Create service account keys](https://docs.cloud.google.com/iam/docs/keys-create-delete)).
5. In the console choose **Google Cloud Storage** and choose the key file or paste its contents.

### MinIO and other S3-compatible

1. Create a bucket, on MinIO for example with `mc mb` ([mc mb](https://docs.min.io/community/minio-object-store/reference/minio-mc/mc-mb.html)).
2. Create an access key for a user whose policy allows the S3 actions in the [checklist](https://docs.sociaro.com/storage/#checklist-for-your-bucket) on the bucket ([mc admin accesskey create](https://docs.min.io/community/minio-object-store/reference/minio-mc-admin/mc-admin-accesskey-create.html)).
3. In the console choose **MinIO** or **Other S3-compatible** and enter the endpoint. It must be a public HTTPS address. Enter the region your service uses, or `us-east-1` if it has none.
4. Keep **Use path-style addressing** on. **MinIO** always uses path-style addressing; if your service only serves buckets as subdomains (`https://<bucket>.<host>`), choose **Other S3-compatible** and turn path-style addressing off.

## Switching

A switch applies to new results, and links always follow the new setting. Changes reach all of our servers within about a minute.

- Switching to Sociaro storage saves new results there. Switching away from Sociaro storage: new results stop being saved to Sociaro storage, but generations already in progress when the setting changes may still finish there.
- Files already on Sociaro storage stay readable and deletable through the API.
- **Files in a former bucket.** After a switch away from a bucket (to another bucket, to Sociaro storage or to no storage), the files in it stay listed. The links the API gives for them now, and private gateway proxy links, no longer download, and `DELETE /v2/files/{id}` answers `409` `storage_changed`. Presigned links issued before the switch keep working until they expire, but only while the bucket, the object, the signing key and its read permission still exist. We do not remove these files: read or delete them directly in that bucket.

## Charging with your own bucket

A generation is charged when the render finishes, independently of saving into your bucket. Delivering it again is free. A job is never charged twice.

If your bucket refuses the file or does not answer, the job does not fail at once. It stays `running` and its `error` names the reason:

```json
{"id": "job_5cc8778b79574aaa7ea8fc09caec23e5",
 "status": "running",
 "error": {"type": "invalid_input",
           "code": "byo_storage_error",
           "message": "Your storage refused the result. Check the storage settings in the console; we will deliver it again while the provider keeps the result (until 2026-11-30 12:00 UTC).",
           "storage_reason": "AccessDenied"}}
```

`storage_reason` is what your storage answered: its error code (for example `AccessDenied` or `NoSuchBucket`), `HTTP <status>`, `no answer` or `timeout`.

What happens next:

- We deliver the result again while the provider still keeps it: each time you poll the job, after a short wait that grows up to 10 minutes, and right away on the first poll after you save your storage settings.
- Fix the cause (permissions, bucket name, credentials) and save the settings again. The next poll delivers the result and the job becomes `succeeded`.
- If the provider no longer keeps the result, or the job's deadline passes before the delivery works, the job ends `failed` with `byo_storage_error`. It stays charged.

Timeouts on your bucket: 10 seconds to connect, 60 seconds without any data moving, and 15 minutes in total for a large file. A timeout is reported with `storage_reason` `timeout`.

An upload to `/v2/files` that your bucket refuses for good (for example `AccessDenied` or `NoSuchBucket`) is answered `422` with `byo_storage_error`. If your bucket fails for a passing reason (it says slow down, answers 5xx or times out), the answer is `503` with `unavailable`: send the upload again. In both cases the file is not added to your files. For a large upload, parts may remain in your bucket until your lifecycle rule removes them (see the [checklist](https://docs.sociaro.com/storage/#checklist-for-your-bucket)), and after an interrupted upload the object may exist in your bucket without a file record.

## Limits

- Up to 16 writes into your bucket at the same time per organisation. Above that, an upload is answered `429` with `Retry-After`. A job output waiting for its turn is simply delivered on a later poll, with no error.
- Deletes and downloads from your bucket have their own per-organisation shares. Above them you get `429` with `Retry-After`. Wait that many seconds and send the request again.

## Checklist for your bucket

- **S3-compatible:** the key needs `s3:PutObject`, `s3:GetObject` and `s3:DeleteObject` on `<bucket>/<prefix>/*`, and `s3:AbortMultipartUpload` for large files. The same permissions apply to R2 and MinIO.
- **Google Cloud Storage:** the service account needs `storage.objects.create`, `storage.objects.get` and `storage.objects.delete` on the bucket or prefix.
- **CORS is not needed.** Our requests to your bucket do not come from a browser. Add CORS only if your own web pages read the links.
- **Lifecycle rules are yours.** We delete from your current bucket only the test object, files you delete through the API, and files past their retention period of up to ten years. We never remove files in a former bucket: delete them there. Set your own expiry if you want an earlier one. A rule that aborts incomplete multipart uploads after 1 day is a good idea.
- With presigned delivery keep the bucket private. With a public URL make sure the address serves the objects.
