Daniel N wrote:
while reading through the agile web development book, i was kind of
surprised to see that uploaded files were stored in the database.
this isn't anything new, but it was the first time i had seen file
uploads handled this way. it seems like that's the way most of the
articles and tutorials i've found have shown to do it. why is this? is
there something better about storing the file in the database, or
sorry if this has been posted a hundred times before, there was
i could find on why most rails apps handle files this way.
I don't know that I'd say *most* rails apps handle files this way. Certainly there are some situations where this is done, but I would hazzard a guess that this is a minority of times.
ActsAsAttachment defaults to filesystem, but gives the option of db storeage. I guess it's up to personal preference.
There have been some very large threads on the rails list a while ago regarding this that went into a lot of detail.
A very quick search at www.ruby-forum.com <http://www.ruby-forum.com> turned up
Hope that helps
I imagine the points if discussion are:
1. If it's in the DB, it scales well - when you move to a multi-server architecture for hosting your application, the data from the DB will be available to all processes.. whereas you may have some concerns if the file you want is stored on the file system of one server.
2. If it's in the DB, it's very easy to protect access to the data by using a controller. It's slightly (not much) more complicated if you're storing it on the file system.
3. I imagine that if you do not want to protect access to your file (i.e., it is stored in a publicly accessible location), then it may be slightly faster to serve it up as 'static content' by getting the webserver to send it out rather than sending it through the application server.
However, I may be wrong in all the points above..