SimpleNS LogoDocs

File Attachments

Upload, store, and attach files to notifications using MinIO / S3-compatible object storage, with per-provider validation and automatic cleanup.


Overview

SimpleNS lets you attach files (invoices, PDFs, images, reports) to notifications across supported channels. Instead of stuffing large binary files into Kafka messages or MongoDB documents, SimpleNS follows a upload-first, reference-by-ID workflow:

  1. Upload the file once to SimpleNS (POST /api/file/upload or via the Dashboard).
  2. SimpleNS stores the file in your configured object storage (MinIO / S3-compatible), deduplicates identical files using a SHA-256 hash, and returns a file metadata record with an id.
  3. Send a notification referencing the uploaded file in content.attachments (or content.<channel>.attachments).
  4. At dispatch time, the Unified Processor downloads the file and hands it to the delivery plugin (buffer, stream, and url).

Why upload first?

Uploading first keeps your notification API requests fast and lightweight, avoids Kafka message size limits, and allows multiple notifications to reuse the same stored file without re-uploading it.


Storage Provider Setup

SimpleNS uses a single active storage provider at a time. Currently, the built-in storage provider is minio, which works with both self-hosted MinIO and any S3-compatible object storage service.

Configuration Fields (minio)

FieldRequiredDefaultDescription
endPointYes—Hostname or IP of the MinIO/S3 server (without protocol).
portNo9000Port number for the object storage API.
useSSLNofalseSet to true for HTTPS connections.
accessKeyYes—Access key / username.
secretKeyYes—Secret key / password (encrypted at rest in MongoDB).
bucketYes—Target bucket name where attachments are stored.
regionNous-east-1Storage region.

Encryption at Rest

Storage provider credentials are encrypted in MongoDB using ADMIN_ALERT_ENCRYPTION_KEY (if set in .env) or an automatically generated encryption key. Keep ADMIN_ALERT_ENCRYPTION_KEY consistent across restarts and replicas in production.

Setting Up via Admin Dashboard

Open Storage Settings Go to Storage (/storage) in the Admin Dashboard.

Add & Test Connection Click Add Storage Provider, choose MinIO, enter your endpoint, bucket, and credentials, and click Test Connection to verify SimpleNS can reach the bucket.

Activate the Provider Save the provider and click Activate. Only one storage provider is active at a time.


Uploading and Sending Attachments

Step 1: Upload a File

Upload files using multipart/form-data to POST /api/file/upload. You can authenticate with either an Admin session or a notification-scoped API key.

Optional query parameters ?channel=<channel>&provider=<provider> tell SimpleNS to validate the upload against that specific provider's file size, count, and MIME type rules right away.

curl -X POST "http://localhost:3000/api/file/upload?channel=email&provider=resend" \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -F "file=@./invoice.pdf"
import axios from 'axios';
import FormData from 'form-data';
import fs from 'fs';

const form = new FormData();
form.append('file', fs.createReadStream('./invoice.pdf'));

const { data } = await axios.post(
  'http://localhost:3000/api/file/upload?channel=email&provider=resend',
  form,
  {
    headers: {
      ...form.getHeaders(),
      Authorization: 'Bearer <YOUR_API_KEY>',
    },
  }
);
// Returns { success: true, files: [{ id, filename, mime_type, size, hash, url, created_at }] }
// e.g., data.files[0].id

Step 2: Reference the File in a Notification

Pass the returned file metadata in content.attachments (or inside a channel-specific block like content.email.attachments):

{
  "request_id": "550e8400-e29b-41d4-a716-446655440000",
  "client_id": "c10e8400-e29b-41d4-a716-446655440000",
  "channel": ["email"],
  "webhook_url": "https://your-app.com/webhooks/simplens",
  "recipient": {
    "email": "user@example.com"
  },
  "content": {
    "email": {
      "subject": "Your Invoice",
      "html": "<p>Please find your invoice attached.</p>",
      "attachments": [
        {
          "id": "file_abc123",
          "filename": "invoice.pdf",
          "mime_type": "application/pdf",
          "size": 48210,
          "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        }
      ]
    }
  }
}

Using the Dashboard

When sending a test notification from Send (/send) or building a payload in Payload Studio (/payload-studio), SimpleNS automatically renders a file uploader whenever the selected provider supports attachment fields.


Limits, Deduplication & Cleanup

Global vs. Provider Limits

SimpleNS enforces limits at two levels:

  1. Global Operational Settings (configured live in Dashboard Settings /settings):
    • attachment.max_file_size: 1 KB to 500 MB (default: 100 MB)
    • attachment.max_file_count: 1 to 50 files per notification (default: 10)
  2. Per-Provider Config:
    • Plugins can declare fileAttachment limits (enabled, maxFileSize, maxCount, allowedMimeTypes) in their manifest or getFileAttachmentConfig().
    • Administrators can also override these limits per provider instance.

Deduplication & Concurrency

  • SHA-256 Deduplication: Every upload is streamed through HashingAndMeteringStream to compute its SHA-256 hash and exact byte size. Duplicate uploads reuse the existing stored object.
  • Distributed Upload Locks: UploadLockService (backed by Redis) prevents race conditions when identical files are uploaded concurrently.

Automatic Retention & Cleanup

The Recovery Service runs a periodic cleanup job (cleanupDeliveredFileAttachments):

  • Delivered notifications: Attachments are automatically deleted from both object storage and MongoDB (file_attachment_model) once recovery.cleanup_delivered_attachments_retention_ms elapses after delivery (default: 86400000 ms / 24 hours, minimum 60000 ms). Setting this to 0 or null disables automatic cleanup.
  • Orphaned files: Uploaded files that are never referenced or whose notifications are cleaned up are also removed safely.

Failure & Retry Behavior

  • If the Unified Processor fails to download an attachment from object storage during dispatch, the notification is retried automatically via the delayed retry queue.
  • If a notification includes attachments for a provider that has disabled attachments, the delivery fails immediately as a non-retryable error.
  • You can inspect attachment metadata and download attached files directly from Events (/events/[id]) in the Admin Dashboard.

On this page