Short answer: keep the export private, give the browser a short-lived presigned GET URL only after the file is complete, and make the object key unique per export attempt. For large B2B SaaS exports, that split matters more than the SDK choice: the worker handles bytes and retries, while the application controls who may request a link and when the artifact is deleted.
The concrete flow is small. An authenticated user starts an export for one tenant. A worker validates and writes the CSV, PDF, or ZIP to a private bucket. The service records the object key and readiness, then signs a GET request for the browser. The browser downloads the bytes from storage; it never receives a storage credential.
That last part is the boundary I want in an eval harness too. Export files can contain prompt fragments, retrieved passages, scores, or tool output. A link that stays valid forever is an access policy pretending to be a convenience.
The artifact has three identities
The first failure is a memory failure. Proxying a multi-gigabyte file through a Node.js route adds application bandwidth, buffering risk, and another timeout to the path. A direct storage download removes that hop, but the worker still needs a bounded-memory export strategy: stream rows into the writer, use multipart upload for genuinely large objects, and measure the time from first byte to completed object.
The second failure is a lifecycle race. URL expiry and object deletion are separate clocks. An expired URL does not delete the object, and a lifecycle rule does not revoke a URL that was already copied. Keep the object private, record delete_at, and make cleanup idempotent. The deletion worker should be able to retry without turning a missing object into a user-visible incident.
The third failure is tenant confusion. A filename is not an authorization check. Every request that creates a link must verify both the job owner and the job state; every retry must preserve the tenant association.
Small tests. Expensive bugs avoided.
I test this with two tenants, an expired URL, a duplicate delivery, a malformed row, and a refresh while rendering is still running. A long export can start as a CSV with a few thousand rows and finish as a ZIP containing several gigabytes, so a happy-path test that only checks HTTP 200 says very little about throughput or cleanup.
A Python worker can make the handoff explicit
Use a job record with tenant_id, job_id, object_key, state, and delete_at. The worker should write to a new key such as exports/tenant-42/job-724/attempt-2.csv, rather than racing to replace latest.csv. Once the upload succeeds, the API checks that the requesting principal owns the job and asks the storage SDK for a presigned GET URL. A 15-minute expiry is an example policy, not a universal answer.
The example below keeps the storage operation in Python because that is where I usually keep the export worker. The same contract works with a Node.js API: ready is the handoff point, and the API returns a capability rather than proxying a large response through its own process. I've kept validation explicit because a notebook export that quietly emits a malformed row is much harder to diagnose after it becomes a customer-facing file.
import csv
import io
import os
import uuid
from collections.abc import Iterable, Mapping
import boto3
FIELDS = ("run_id", "score", "model")
def create_export(
rows: Iterable[Mapping[str, object]], tenant_id: str
) -> tuple[str, str]:
materialized = list(rows)
for row_number, row in enumerate(materialized, start=1):
missing = [field for field in FIELDS if field not in row]
if missing:
raise ValueError(f"row {row_number} is missing: {', '.join(missing)}")
content = io.StringIO(newline="")
writer = csv.DictWriter(content, fieldnames=FIELDS)
writer.writeheader()
writer.writerows(
{field: row[field] for field in FIELDS} for row in materialized
)
bucket = os.environ["EXPORT_BUCKET"]
key = f"exports/{tenant_id}/{uuid.uuid4()}.csv"
client = boto3.client("s3")
client.put_object(
Bucket=bucket,
Key=key,
Body=content.getvalue().encode("utf-8"),
ContentType="text/csv",
)
url = client.generate_presigned_url(
ClientMethod="get_object",
Params={
"Bucket": bucket,
"Key": key,
"ResponseContentDisposition": "attachment; filename=eval-runs.csv",
},
ExpiresIn=900,
HttpMethod="GET",
)
return key, url
if __name__ == "__main__":
export_key, download_url = create_export(
[
{"run_id": "run-101", "score": 0.84, "model": "candidate-a"},
{"run_id": "run-102", "score": 0.91, "model": "candidate-b"},
],
tenant_id="tenant-42",
)
print({"object_key": export_key, "download_url": download_url})
The code demonstrates a useful order: validate rows, choose an immutable key, upload the complete object, and only then sign the GET. It does not demonstrate authentication, because credentials and tenant authorization belong in the application boundary, not in a copied snippet. In production, store the job state transactionally and never log the complete URL.
The storage contract is easier to compare than the products behind it:
| Delivery shape | Application work | Large-file path | Main boundary |
|---|---|---|---|
| Presigned GET | Authorize and sign | Browser reads storage directly | URL is a bearer capability |
| Application proxy | Authenticate and stream | Application carries the bytes | App bandwidth and timeout budget |
| Public object URL | Publish an object | Browser reads without a private gate | Unsuitable for private tenant exports |
For this use case, the first row usually keeps the throughput path shortest. The last row is disqualified by the requirement that signed documents remain private until their deletion deadline.
The useful state machine is requested -> rendering -> ready -> expired -> deleted. The object key belongs to the ready state, the signed URL belongs to a particular download request, and the deletion deadline belongs to the job record. Those are deliberately different identities. If a client refreshes a page, the API can issue another capability for the same ready object without asking the worker to render the report again; if a worker retries, it can write a new attempt and let the database select the current one; if cleanup runs twice, the second pass can record that there is nothing left to remove. I want these transitions in an eval harness because each one is a testable contract, and because throughput numbers without state correctness are a polished way to ship duplicate files.
Can a browser safely consume a private export URL?
Presigned URLs are bearer capabilities: possession is enough until the signature expires. Keep them out of logs, analytics payloads, support tickets, and publicly cacheable API responses. The download can be a top-level browser navigation, which often avoids making frontend JavaScript read the response body. If JavaScript must fetch the object, configure CORS for the exact origins and methods required; CORS is a browser access-control mechanism, not a replacement for object authorization.
Large files also change retry behavior. A failed browser transfer should not automatically create a second export job. Keep the artifact identity separate from the link identity: the same ready object can receive a newly signed URL, while a new export gets a new key. That distinction makes notebook-to-prod behavior easier to evaluate because a retry is observable instead of silently producing duplicate artifacts.
I’m not sure a single expiry value can satisfy every tenant. A short window reduces exposure but frustrates a slow connection; a longer window improves completion probability but extends bearer access. Measure download completion and link-regeneration rates, then set policy from those observations rather than copying a number from an example.
The launch decision is a retention contract
Start with a failure matrix, not a vendor comparison. Verify that an unauthenticated caller cannot create a link, that tenant A cannot request tenant B’s job, and that a job in running state has no downloadable key. Verify that the response sends the intended filename and content type, and that a URL past its expiry is rejected by storage. Check that logs redact query strings and that cleanup reaches old objects even after a worker retry. I treat a 403 during an expiry test as evidence to inspect the capability boundary, not as a reason to grant the application a broader storage credential.
Then load-test the real shape of the artifact. Track peak worker memory, upload throughput, time to readiness, time to first browser byte, completion rate, and cleanup lag. Compare direct download with an application proxy using the same file size and network conditions. Your mileage may vary: a 20 MB CSV and a 2 GB ZIP exercise different bottlenecks.
The catch is that presigned delivery is a narrow tool. It is not suitable when the product needs public distribution, browser-side upload with a different trust model, version recovery, immutable retention, cross-region replication, or a provider feature your storage abstraction cannot expose. Stick with a direct provider integration when its control plane is a hard requirement; use a separate artifact service when search, retention holds, or audit workflows are the primary problem.
For the stated B2B SaaS case, the decision rule is straightforward: generate once, store privately under a unique key, authorize the job, sign only a ready object, and delete it on an explicit schedule. The important engineering work is the state machine around the URL. The URL itself is the easy part.
Top comments (1)
URL 过期和对象删除是两把时钟这点很关键,我之前只设了过期时间,结果链接失效了文件还一直躺在桶里。后来改成 job 记录里单独记 delete_at,删除 worker 幂等重试,过期链接和残留文件才都收得住。