I'm working on a website that will allow users to upload PDF files, and I'm trying to figure out the best way to store these files on the server. I've heard that storing files in a database isn't very efficient or scalable, but if I just store them directly on my VPS, I can access them like regular files through the Linux filesystem. However, that feels a bit unsafe. The only other option I've considered is using cloud storage, but I'm not very familiar with it and I've heard some concerning stories about unexpected costs. What should I do?
4 Answers
From my experience as a full-stack developer, I'd suggest considering a cloud service for file storage. Azure storage containers, for example, is great because it allows you to manage access and keeps your server space free. Users upload files, which you save in the cloud with a unique ID for retrieval later. This way, you have better control over access, and you can choose to prevent public access entirely.
It's possible to store files directly in a database, but keep in mind that would typically use more disk space, especially if you're encoding them in base64. Otherwise, accessing them through the filesystem could be more efficient.
If you're worried about server security, what exactly doesn't feel safe about storing files directly? There are definitely risks, like potential viruses in PDFs, especially if you're new to handling file uploads. You might want to look into ways to secure your server during the uploads.
One straightforward solution is to compress the PDFs into a zip file before storing them. It can help save space and might make handling the files easier!

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads