Skip to main content

Digital Signatures & Image Streaming (/api/signatures/[id])

Email signatures and inline campaign imagery in serverless and containerized environments face a persistent challenge: serverless platforms (such as Vercel or read-only Azure container instances) provide a strictly read-only local filesystem. Storing dynamically uploaded signatures to local disk throws EROFS: read-only file system.

veridex-hitech-web-application solves this through MongoDB Database Persistence paired with an Immutable Public Streaming Route (/api/signatures/[id]).


1. Architectural Challenge & Solution​


2. Public Image Streaming Endpoint (GET /api/signatures/[id])​

Located at src/app/api/signatures/[id]/route.ts:

  • Execution: Publicly accessible route (export const dynamic = "force-dynamic").
  • Validation: Validates that :id is a syntactically valid MongoDB ObjectId.
  • Decoding: Extracts the raw binary content from the stored base64 data URI using regular expression pattern matching:
    const matches = sig.imageData.match(/^data:([A-Za-z0-9\-+/]+);base64,(.+)$/);
    const contentType = matches ? matches[1] : sig.contentType || "image/png";
    const base64Content = matches ? matches[2] : sig.imageData;
    const buffer = Buffer.from(base64Content, "base64");
  • Caching Headers: Emits Cache-Control: public, max-age=31536000, immutable. Because database signatures are identified by immutable ObjectId keys, browsers and edge CDNs can cache the binary asset for up to one full year (31,536,000 seconds) without re-validating with the origin database.

3. Signature Management in the Admin Suite​

In the Admin Bulk Email tab:

  • Signature Gallery: Displays scrollable thumbnails of all active signatures stored in MongoDB.
  • Upload New Signature: Administrators can upload custom agency signature banners (PNG, JPEG, WebP) with a human-readable title.
  • System Default Protection: Default templates and system signatures are flagged with isSystemDefault: true, protecting them from accidental deletion.
  • Deletion Protocol: Administrators can delete outdated custom signatures with prompt confirmation.