This task is one section of Eight software practices that keep business apps reliable, with 7 related tasks on one page.
1. Pick a store
Put uploads on a disk or object store that survives a restart of the web process. Keep the path or object key on the record, with the owner.
2. Limit what you accept
Allow the types the feature needs and a maximum size. Reject the rest before you save.
3. Check the owner
Download as the owner and succeed. Download as another user and fail. Guessing a nearby id must not return the file.
4. Delete with the record
When the business record is removed, remove or retain the file on purpose. Do not leave customer files with no owner.
5. Frequently asked questions
Can I store files in the database?
You can for small files, but large uploads will bloat backups. Decide before the first real customer file.
Should the file name be the download name?
Show a safe display name. Do not trust the original path from the browser.
What about a public brochure?
Mark it public on purpose. Everything else stays private to the owner.
6. Related articles and next steps
Treat the checks below as the acceptance test for the change. Names of libraries can vary; the behavior to prove does not.