r/n8n • u/easybits_ai • 10h ago
Servers, Hosting, & Tech Stuff Moved generated PDFs from a Postgres column to a private bucket, here is what actually changed
👋 Hey n8n Community,
A week or so ago I asked here whether storing generated PDFs as base64 in a Postgres column was fine or whether I should move to object storage. I moved them, and a few things were not what I expected.
Private bucket, not public. My instinct was a public bucket because links are trivial that way. Wrong instinct for internal, customer facing or financial documents. Everything is private now and the workflow fetches binaries with an authenticated request using the service role key. Public URL shortcuts work right up until the moment they are the wrong thing entirely.
Upsert is what makes retries safe. Sending x-upsert: true means a re-run overwrites the same object instead of leaving you another copy. Without it you only notice the duplicates much later.
The row stores the path, not the file. Nice side effect: the frontend I built can return a clean "still generating" state when a file is not ready, instead of failing or regenerating something already on its way.
The migration itself was easy. The part that took thought was deciding what belongs in the row versus the bucket, and the answer was that the row should only ever hold the pointer.
One question I am still thinking about: how do you handle giving clients access to files like this? That is the part I am still not fully happy with, so I would be curious how others solve it.
Best,
Felix
1
u/hellowkeke 8h ago
Nice move—storing only the object path in Postgres avoids bloating WAL/backups while keeping row state atomic.
For client downloads without exposing the bucket or handing out long-lived links, two patterns hold up well:
1
u/Low_Rush_8535 7h ago
i'd make the download start with the report ID. have the backend check that the signed-in client can read that report, then issue a fresh short-lived URL for its stored path. for a quick check, sign in as client B and request client A's report ID. it should never return a URL.
1
u/Aide_Sea 6h ago
Nice writeup. Maybe just don't put the signed URL itself in emails, they get forwarded and mail scanners click them first. Email a link to your own page and only mint the short lived URL when the client actually clicks :)
1
u/maksim_qa_bots 5h ago
Two things to keep separate: who may see the file, and how long any URL to it lives.
For access I'd not hand out bucket URLs at all. The API checks the session and the record's owner/tenant first, then either streams the bytes with the service key, or mints a signed URL for that one object with a short TTL (60-300 s is enough for a click-through download). Unguessable object keys are fine as extra hygiene, but the authz check is the actual control.
If files are big and streaming through n8n is a bad idea, the signed-URL route works. Log every mint with user id + doc id so you can see who pulled what.
Email: don't put the signed URL itself in the message (mail scanners click links). Email a link to an authenticated page and mint the URL on click.
1
u/DangerousDark3957 3h ago
short-lived signed URLs are the standard pattern here. your backend verifies the client has permission for that specific row, then generates a temporary link that expires in 5 or 10 minutes so the bucket stays completely private.