|
I am working on an Rails 3 application which accepts user uploaded image. Currently the images are getting stored inside the public dir of my app. But considering a scenario where I want to upgrade my rails app to a new one, I will always have to keep this public directory same for all versions of my app in order for the DB to exactly retrieve and thus show the image. Basically the link / path to the image is stored in the DB and the actual image is getting stored inside the public dir of the app. I have read many links to understand the way the uploaded images, etc needs to be stored and have come across 2 approaches: File System Storage VS Database Storage. Due to performance and various other reasons, I prefer the File System Storage option but I am confused as how should I design it. Definitely storing in public folder of the app is not a good idea. I also thought of storing in another dir under my ~/webapps/ and then have my app always access this path for images. This way they both remain decoupled. But again in this approach, I have to still maintain and ensure that the web apps folder always remains fine and is backed up regularly for restoration purpose. Can someone please suggest me and guide me the correct design approach? I am sure most of the common web apps demands images to be stored and there is some standardized way for the same. Thanks for your help and response. |
|
File system storage is usually better from performance point of view - so you are on the right track there. You can store these files under ~/webapps/appname provided that's outsite the web root of the app (as defined in your nginx.conf file). You could also store in any folder under your home directory - it's up to you, and as far as I'm aware there's no standard or best practice that would suggest storing those files in a certain location. Regarding backing up that folder, you can schedule a cronjob to do that for you - again, it doesn't matter where on the filesystem this folder is located, it just needs to be referenced correctly by your cron script. If you run into any troubles setting this up, feel free to post a comment to this answer, or open a ticket. |