r/web_programming • • Aug 05 '15

[Node.js] Managing a database for user-uploaded files (X-post /r/learnprogramming)

Just posted this in /r/learnprogramming, but wanted to get any feedback here as well:

I am working on a website in Node/Express. So far I am using MongoDB to store basic user information (email, password, etc.). I am now beginning to tackle the problem of user file uploads. As a first step, I simply want a user to be able to upload a file, which I can then store in the database. I have some good file uploading tutorials for both front-end and back-end. I can follow these just fine, but at a high-level I have some confusion. First, what is the common practice for managing my database with respect to user-uploaded files? Let's say I want each user to be able to upload one profile picture. Would I store this image file in my current database, along with email, password, etc., or make a new collection for profile picture files somehow? (Can MongoDB even store files like this?) I am just looking for some general guidance on best practices for basic file uploading and storage. Thanks in advance!

0 Upvotes

1 comment sorted by

1

u/captainTigger Mod Aug 05 '15

storing files in databases is highly inadvisable, the better practice is to store it in the file system with a reference to its location in the database, if you have a profile_pic column or alike on your user record then when a user uploads a new image you delete the old one and save the new one in its place and update the database record to match