Jump to content

Store PDFs in Database or File System

Recommended Posts


Do you know that in some parts of the world, electronic invoices need to be preserved in an immutable form?
Picture this: You issue an invoice, and it’s as untouchable as a museum artifact. But how do you keep it safe?
Well, you could stash it in your database, but not just as plain old rows — they need fortification. Think PDFs snugly tucked within your database’s digital embrace.
Now, here come the big decisions.

Option one:
You cram those PDFs into a BLOB or CLOB, making them feel cozy within a database row.

Example of using a BLOB to store the file within a row in the database:

CREATE TABLE invoices (
file_name VARCHAR(255) NOT NULL,
file_data BLOB NOT NULL

Option two:
You let those files roam free on your file system while keeping a watchful eye on their metadata — names, locations, dates, and the like — stored safely in your database.

Example of storing the file on the file system and recording the metadata in the database:

CREATE TABLE invoices (
    file_name VARCHAR(255) NOT NULL,
    file_path VARCHAR(255) NOT NULL,

As to the great file-handling debate! When it comes to managing your electronic treasures, you’ve got options. For Go and Python, it’s as easy as pie — just reach for the ospackage. It’s like the Swiss Army knife of file handling, always ready to lend a helping hand.
Meanwhile, over in Node land, they’ve got their trusty sidekick, fs, to tackle all things file-related. And let’s not forget about Rust, with its steadfast std::fs library by its side.
It’s true that storing files in your database can be pricier than letting them loose on the file system, but sometimes you need that fortress-like protection. After all, keeping track of the integrity between your database and file system is like herding cats — way too complicated!
In this end, just remember: when it comes to safeguarding your precious electronic documents, it’s all about finding the right balance between security and cost. And who said invoices couldn’t have a little adventure?

Link to comment
Share on other sites

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

By using this site you automatically agree to the Privacy Policy | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.