Open MercatoDocsSearch docsAPI reference

User guide

Storage Hub — S3 Integration

Connect S3-compatible storage to the Storage Hub and choose how the application uses it. Verify access against the intended bucket before uploading application files.

The Storage Hub lets you route attachment storage to a cloud object store instead of the local filesystem. Once configured, all new file uploads for an attachment partition are transparently written to S3 (or any S3-compatible service). Existing local-filesystem attachments continue to work side-by-side with no data migration required.

How it works

Open Mercato uses a pluggable storage driver architecture. Each attachment partition declares which driver to use (local by default). When you configure S3 credentials and switch a partition's driver, all new uploads for that partition go to S3 while reads from older local-filesystem files continue to work through the local driver.

The integration also exposes standalone S3 API endpoints that let you upload, download, delete, and pre-sign URLs for files entirely outside the attachments module – useful for custom integrations or workflows that need direct S3 access.

Prerequisites

Enable the module

Add the environment variable to your deployment before starting the app:

OM_ENABLE_STORAGE_S3=true

After the first start with this flag set, the S3 integration card appears in External Systems → Integrations.

Step 1 – Enter S3 credentials

  1. Navigate to External Systems → Integrations and click Configure on the S3 Object Storage card.
  2. Open the Credentials tab and fill in the connection details.

FieldRequiredDescription
Access Key IDYesAWS access key ID (or equivalent for your provider)
Secret Access KeyYesAWS secret access key
RegionYese.g. us-east-1, eu-west-1, nyc3 for DigitalOcean
BucketYesName of the pre-created bucket
Endpoint URLNoCustom endpoint for non-AWS providers (see table below)
Force Path StyleNoRequired for MinIO and some self-hosted S3 services
  1. Click Save Credentials.

Provider endpoint reference

ProviderEndpoint URLForce Path Style
AWS S3(leave blank)No
DigitalOcean Spaceshttps://<region>.digitaloceanspaces.comNo
MinIO (self-hosted)http://<host>:<port>Yes
Cloudflare R2https://<account-id>.r2.cloudflarestorage.comNo
Backblaze B2https://s3.<region>.backblazeb2.comNo

Conditional-write compatibility

The provider must enforce atomic conditional PUT with If-None-Match: *. Attachment and standalone S3 uploads send this header so a new upload cannot overwrite an existing object, including objects not yet tracked by quota accounting. Supporting the S3 API or accepting this header without enforcing it is insufficient.

ProviderConditional PUT compatibility
AWS S3Documents create-only writes using If-None-Match: *.
MinIOAIStor documents If-None-Match on PutObject. Verify the installed server version, especially older or community deployments.
Cloudflare R2Documents atomic conditional PutObject, including rejecting concurrent writes to the same key.
DigitalOcean SpacesIts S3 compatibility reference does not explicitly confirm conditional PUT semantics. Verify with the provider and test the target endpoint before using it for uploads.
Backblaze B2Its S3 PutObject reference does not explicitly confirm If-None-Match support. Verify with the provider and test the target endpoint before using it for uploads.

These are provider documentation references, not results of Open Mercato live-provider certification. In a disposable test bucket, confirm that a conditional PUT to a new key succeeds and a second conditional PUT to that key fails while preserving the original bytes. A passing connection health check only checks bucket access; it does not verify conditional writes. Repeat compatibility checks after provider or proxy upgrades.

When quota accounting already knows the target key, standalone upload admission returns 409. If the object exists only at the provider, the provider rejects the conditional write (AWS S3 uses 412 Precondition Failed; concurrent operations can return 409). Open Mercato surfaces a failed upload; provider status codes are not necessarily passed through unchanged. Choose a new key instead of retrying an overwrite.

A provider that rejects conditional PUT as unsupported causes uploads to fail. A provider or intermediary that silently ignores the header can permit overwrites and is incompatible with the storage safety guarantees. Do not remove the header to work around an upload failure.

Step 2 – Verify the connection

After saving, open the Health tab and click Check Health to confirm the credentials are valid and the bucket is reachable.

S3 integration health tab showing a passing health check

If the check fails, review the error message. Common causes: wrong region, bucket does not exist, or missing s3:PutObject / s3:GetObject permissions on the IAM policy.

Step 3 – Configure an attachment partition to use S3

  1. Open Settings → Attachments → Partitions.
  2. Click Edit on the partition you want to move to S3 (or create a new partition).
  3. In the Storage Driver dropdown, select Amazon S3.
    • If you don't see (or can't select) Amazon S3, make sure OM_ENABLE_STORAGE_S3=true is set and the app was restarted.
  4. Fill in the S3 settings for this partition.
    • The Bucket/Region/Endpoint here are the ones used by the attachments S3 driver for this partition.
    • In most setups you should keep them consistent with the S3 Integration credentials to avoid confusion, but they are applied separately.
  5. Click Save.

Attachment partition settings with Storage Driver dropdown set to S3

All new files uploaded to this partition from this point forward are stored in S3. The key structure used inside the bucket is:

<partition-code>/org_<orgId>/tenant_<tenantId>/<timestamp>_<uuid>_<filename>

Info

Existing files already uploaded to the local filesystem remain accessible and are served through the local driver. You do not need to migrate them unless you want to.

Environment-based preconfiguration

If your deployment already has S3 credentials at boot time, you can skip the UI form by setting env vars:

OM_ENABLE_STORAGE_S3=true
OM_INTEGRATION_STORAGE_S3_ACCESS_KEY_ID="<om-integration-storage-s3-access-key-id>"
OM_INTEGRATION_STORAGE_S3_SECRET_ACCESS_KEY="<om-integration-storage-s3-secret-access-key>"
OM_INTEGRATION_STORAGE_S3_REGION=us-east-1
OM_INTEGRATION_STORAGE_S3_BUCKET=my-mercato-bucket
# Optional:
# OM_INTEGRATION_STORAGE_S3_SESSION_TOKEN=
# OM_INTEGRATION_STORAGE_S3_ENDPOINT=https://nyc3.digitaloceanspaces.com
# OM_INTEGRATION_STORAGE_S3_FORCE_PATH_STYLE=true
# OM_INTEGRATION_STORAGE_S3_FORCE_PRECONFIGURE=false

OM_ENABLE_STORAGE_S3=true is the module-enablement gate: without it the storage_s3 module is not registered in enabledModules and the rest of the OM_INTEGRATION_STORAGE_S3_* block is ignored. The two layers are intentionally separate so you can preview the integration card in the UI without preconfiguring credentials.

On new tenant setup the module reads OM_INTEGRATION_STORAGE_S3_* and pre-populates the Integration Marketplace credentials so no manual configuration step is needed. Setup failures (for example a partial env block) are surfaced through the Integrations → Logs UI under the storage_s3 filter, so operators can see them alongside other integration activity.

Preconfigure existing tenants from the CLI

onTenantCreated only runs once per tenant. If you upgrade an existing deployment after setting the OM_INTEGRATION_STORAGE_S3_* block, rerun the provider CLI to apply the preset to a tenant that was provisioned before the variables were available:

yarn mercato storage_s3 configure-from-env --tenant <tenantId> --org <organizationId>

Behavior:

Use --force when you want to roll keys without going through the Integrations UI:

yarn mercato storage_s3 configure-from-env \
  --tenant <tenantId> \
  --org <organizationId> \
  --force

Apply to every tenant from a deploy hook (--all-tenants)

For unattended deploys – Dokploy, Coolify, Kamal, plain docker run, etc. – you usually do not want to track tenant and organization UUIDs in your deploy configuration. Use --all-tenants instead: the CLI iterates every active organization in the database and applies the preset to each (tenantId, organizationId) pair.

yarn mercato storage_s3 configure-from-env --all-tenants

Use it as a post-deploy / release hook in your platform (e.g. a Dokploy "deploy command", a Kamal accessory post-deploy, a Coolify "after deployment" step). On every redeploy, the command:

Exit code semantics:

--all-tenants cannot be combined with --tenant / --org. Pick one mode per invocation.

Local development with LocalStack

For local development and integration testing you can run a local S3 stub using LocalStack. Start it alongside the other infrastructure services by enabling the storage-s3 compose profile:

docker compose --project-directory . -f starters/docker/compose.infra.yml --profile storage-s3 up -d

Then configure your local .env:

OM_ENABLE_STORAGE_S3=true
OM_INTEGRATION_STORAGE_S3_ACCESS_KEY_ID="<om-integration-storage-s3-access-key-id>"
OM_INTEGRATION_STORAGE_S3_SECRET_ACCESS_KEY="<om-integration-storage-s3-secret-access-key>"
OM_INTEGRATION_STORAGE_S3_REGION=us-east-1
OM_INTEGRATION_STORAGE_S3_BUCKET=mercato-dev
OM_INTEGRATION_STORAGE_S3_ENDPOINT=http://localhost:4566
OM_INTEGRATION_STORAGE_S3_FORCE_PATH_STYLE=true

Create the test bucket before the first run:

aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket mercato-dev

Note

LocalStack is not included in the default yarn infra:up. It only starts when the storage-s3 profile is active to keep the default dev loop lightweight.

Standalone S3 API

The storage_s3 module also exposes API endpoints for direct S3 file operations without going through the attachments module. All routes require authentication and the storage_providers.manage feature.

All keys passed to these endpoints must be scoped to the authenticated tenant's org_<orgId>/tenant_<tenantId>/ namespace.

MethodPathDescription
POST/api/storage-providers/s3/uploadUpload a file (multipart/form-data)
GET/api/storage-providers/s3/download?key=…Download a file by S3 key
POST/api/storage-providers/s3/signed-urlGenerate a pre-signed upload or download URL
DELETE/api/storage-providers/s3/deleteDelete a file by S3 key
GET/api/storage-providers/s3/list?prefix=…List files by prefix (auto-scoped to tenant)

Upload example

curl -X POST https://your-app/api/storage-providers/s3/upload \
  -H "Authorization: Bearer <token>" \
  -F "file=@/path/to/document.pdf"

Response:

{
  "key": "uploads/org_<orgId>/tenant_<tenantId>/1714300000000_abc123_document.pdf",
  "bucket": "my-mercato-bucket",
  "size": 104523,
  "contentType": "application/pdf"
}

Pre-signed URL example

curl -X POST https://your-app/api/storage-providers/s3/signed-url \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"key":"uploads/org_x/tenant_y/file.pdf","operation":"download","expiresIn":3600}'

Response:

{
  "url": "https://my-bucket.s3.amazonaws.com/uploads/...?X-Amz-Signature=...",
  "expiresAt": "2026-04-28T14:00:00.000Z"
}

Signed-upload size and quota reservations

For operation: "upload", supply size in bytes when the file size is known. For example, this request reserves 1 MiB for a 1 MiB file:

{
  "key": "uploads/org_<orgId>/tenant_<tenantId>/document.pdf",
  "operation": "upload",
  "contentType": "application/pdf",
  "size": 1048576,
  "expiresIn": 3600
}

The response includes url, expiresAt, and reservationId. Send the file bytes with PUT to the returned one-time application upload URL. The upload proxy enforces size as an upper bound; a larger body is rejected with 413. Download URLs do not reserve upload capacity, and size is ignored for downloads.

Omitting size remains supported, but reserves the configured maximum upload size from resolveAttachmentMaxBytes() instead of the eventual file size. The default is 25 MiB, controlled by OM_ATTACHMENT_MAX_UPLOAD_MB (legacy alias: OPENMERCATO_ATTACHMENT_MAX_UPLOAD_MB). Several unused URLs can therefore exhaust the tenant's available quota even when their intended files are small. Supplying the exact byte size avoids unnecessarily reserving that extra capacity.

After a successful upload, accounting commits the actual bytes stored and releases the unused portion of the reservation. An unused URL retains its reservation until its lease expires and the recovery worker reconciles it. expiresIn controls the initial URL lifetime (default 3,600 seconds; allowed range 60–604,800 seconds). Expiry prevents starting an upload with that token; it does not guarantee that quota is released at that exact instant.

Recovery releases capacity after confirming that no object remains, or commits a valid completed object's actual size. An upload already in progress can require additional lease time and a second absence check. Provider errors or uncertain cleanup keep capacity reserved while recovery retries. Keep the quota-recovery worker operating; allow reconciliation to complete before treating expired URLs as free capacity.

Access control

FeatureGrants
storage_providers.manageConfigure integration credentials, use standalone S3 API

The storage_providers.manage feature is granted to superadmin and admin roles by default. No additional role configuration is needed for standard setups.

Troubleshooting

SymptomLikely causeFix
Upload fails with NoSuchBucketBucket does not exist in the specified regionCreate the bucket or correct the region/endpoint
Upload returns 403 from S3IAM policy missing s3:PutObjectAdd s3:GetObject, s3:PutObject, s3:DeleteObject, s3:ListBucket to the policy
MinIO returns InvalidAccessKeyIdforcePathStyle not setEnable Force Path Style in the credentials form
Attachment served as 404 after switching partition driverFile was uploaded before driver switchThe file is still on local disk – switch the partition back to local, or re-upload
S3 integration is not configured errorOM_ENABLE_STORAGE_S3 not set or credentials not savedVerify env var and re-save credentials via Integrations

Previous: Self-service onboarding · Next: Stripe Payment Gateway