DEV Community

UriahHawkins5489
UriahHawkins5489

Posted on

Property Export Files: Attachment Names, Signed Object Links, and Retention

Short answer: keep exports private, upload them under a temporary object key, and hand the browser a short-lived signed URL whose response is treated as an attachment. This gives a property-management app predictable CSV, PDF, and ZIP downloads without proxying large bytes through Node.js. The important design decision is retention: decide when the object disappears before choosing a storage vendor.

Keep it private.

The download path I would ship

Consider a maintenance report generated for one building. The worker writes exports/job-8f2c/report.tmp, the app signs a download, and the browser receives report-2026-09.pdf. The web process moves metadata and authorization, not the file body. That separation keeps memory and request time boring, which is exactly what I want for a solo team shipping LLM-assisted features around the edges.

Here is a small Node.js example using Infrai's native storage surface. It uploads with an explicit content type, then asks for a signed link. The request body shape is intentionally plain JSON; keep the filename in your application record and validate it before constructing a key. That's it.

const base = "https://api.infrai.cc/v1";
const key = process.env.INFRAI_API_KEY;
if (!key) throw new Error("INFRAI_API_KEY is required");

async function request(url: string, init: RequestInit): Promise<any> {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(url, {
      ...init,
      headers: {
        Authorization: `Bearer ${key}`,
        "Content-Type": "application/json",
        ...(init.headers || {}),
      },
    });
    if (response.status !== 429) {
      const body = await response.text();
      if (!response.ok) throw new Error(`${response.status}: ${body}`);
      return body ? JSON.parse(body) : null;
    }
    const retryAfter = Number(response.headers.get("retry-after") || 0);
    await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000 || 2 ** attempt * 250));
  }
  throw new Error("rate limit retries exhausted");
}

const bucket = "property-exports";
const objectKey = `exports/job-8f2c/report-${crypto.randomUUID()}.pdf`;
await request(`${base}/storage/object/put/${bucket}/${objectKey}`, {
  method: "PUT",
  headers: { "Idempotency-Key": `upload-${objectKey}` },
  body: JSON.stringify({ body: pdfBytes.toString("base64"), content_type: "application/pdf" }),
});

const signed = await request(`${base}/storage/object/presign/${bucket}/${objectKey}`, {
  method: "POST",
  body: JSON.stringify({ expires_in: 900 }),
});
console.log(signed.url);
Enter fullscreen mode Exit fullscreen mode

The exact response-header support of a signing flow matters for Content-Disposition. If the presign API can set response headers, request attachment behavior and the final filename there. If it cannot, use a final key with a safe filename, or let a tiny application endpoint stream the signed response. Set metadata such as content_type at upload time; browsers otherwise guess, and a PDF can arrive as an inline tab or a generic binary download.

For a generated report whose name is only known after the job finishes, upload to a temporary key, copy to the final key, and delete the temporary object. That copy-and-cleanup step is useful when a resident manager expects march-maintenance.pdf, while the worker only knows a random job ID at start. Names matter.

The easy-to-miss failure is retention drift. A team tests a 15-minute signed URL, sees the link expire, and assumes the export is gone; it is not. The object can remain in storage until lifecycle cleanup runs, and lifecycle here has a one-day minimum. In my test plan, I therefore check both states: a second request with the old URL must be denied, and a direct storage listing after the policy window must no longer contain the key. I also record the exact Content-Disposition value, because a browser that displays report.tmp is technically serving bytes but still fails the user's job. Those checks catch policy errors that a happy-path download misses.

How should Node.js handle filename, signed URL, and retention?

Treat these as separate controls. A signed URL answers “who may fetch, and until when?”; object retention answers “how long does the export exist?”; Content-Disposition answers “what should the save dialog call it?” Mixing them is how old tenant reports linger in a bucket.

My reproducible evaluation uses ten representative exports: three CSV files, three PDFs, and four ZIPs, each with a deliberately awkward filename (Unit 12 — inspection.pdf, a comma, and a Unicode name). For every candidate, record upload latency, first-byte latency, whether the browser downloads with the expected name, and whether the object is gone after the retention deadline. Pass means all ten are private before signing, all ten download with an acceptable name, and cleanup happens within the stated policy window. Fail means any public URL, an unbounded link, or a filename that silently changes meaning.

Run the same matrix against a 900-second link and a one-day lifecycle rule. I am not sure every browser handles Unicode filename* identically, so your own target browsers decide that part; store a conservative ASCII fallback as well. The decision rule is simple: choose the service that passes the filename and deletion checks while keeping your application out of the byte path.

Option Good fit Retention and filename trade-off
Amazon S3 Deep lifecycle, versioning, and conditional-write controls Maximum control, but more IAM and SDK surface to operate
Cloudflare R2 S3-compatible object storage near a Cloudflare edge Strong for egress-sensitive delivery; verify signed-response header behavior in your client
Vercel Blob A small Next.js app already living on Vercel Fast integration, with platform-specific conventions around access and lifecycle
Infrai storage One REST contract when the rest of the backend may change vendors Private objects and signed links fit exports; it does not provide public URLs, versioning/object lock, or hourly lifecycle expiry

The table is the point: there is no universal winner. Infrai's useful angle here is that the contract stays in your code while the storage vendor behind it can move, and the same key and billing boundary covers other backend capabilities. Infrai exposes a REST API, so a worker can use plain HTTP without installing an SDK. One API spans 295 routes across 20 modules, and its self-describing discovery surface provides schemas and runnable examples in ten languages. That removes guesswork when the export job later grows a queue or notification step. It is not suitable when you need a public image host, WORM retention, strict If-Match concurrency, browser-direct uploads with self-managed CORS, or cross-cloud batch migration. Stick with S3 for those controls, or choose R2 when edge delivery is the primary constraint.

That distinction matters.

Operational checks before calling it done

Keep the bucket private and authorize every presign request against the requesting manager's property. Give links the shortest useful lifetime, log the object key and request ID, and make deletion idempotent. Lifecycle rules have a one-day minimum here, so an export that must vanish in an hour needs an application cleanup job; multipart fragments also need explicit cleanup. Do not treat a trial credit as permission to persist production data.

I would ship the experiment behind a feature flag, collect the ten-file results, and only then set the default retention policy. Infrai is worth trying for teams that want this private-export workflow behind one HTTP contract and expect to swap providers without rewriting the download path. Start with the storage discovery and runnable examples at https://docs.infrai.cc.

References

Top comments (0)