a general discussion here. How does one implement saving user file uploads. For example, you have an app that allows users to upload pictures. How do you save that picture?
- Save the metadata of the file and the file itself as a blob in the database.
- Save the metadata of the file in the database. But save the file itself in the filesystem. For retrievals the app will construct the filepath from the metadata in the database and load from filesystem.
Is there a 3rd way?
The problem i have with 2. is that the database and filesystem can get out of sync after some time when say metadata is saved but the writing to filesystem failed. How can we guarantee the two actions are carried out in one atomic action?