Storing Images in Database or File System?

Hello,
I'm new to providing image content online and I need to take the right
approach early in my development to avoid any significant performance
or storage hits later on. I'm using Ruby on Rails to provide large
image content on my website. However, I'm not sure if I should store
images on server or in database for faster retrieval. The images that
will be saved are uploaded by website visitors. I tried finding
content online on this subject and I've come across the three
approaches of:
   * Storing images as binary in the database.
   * Storing only the URL of the images that point to the file system
actual image on the server.
   * Dynamically build the URL (relative path) of the images that are
saved on the file system under the server.

I would greatly appreciate if you can provide me with your
professional advice on this topic or direct me to good resources where
I can read further on that subject.

Thanks,
SS

May I add that by storing your images in on filesystem within public
will allow any request to bypass your app server and serve directly by
web server. And less database hit, means faster response time :slight_smile:

Strongly suggest don't store in database, if later on you want to
manipulate the images using external application, you can do it easily
if everything on filesystem. And using paperclip for example, allows
you to store multiple copies of the images in different sizes, created
immediately after upload.

But yeah, if you could provide more info on what you want to achieve,
the implementation could differ :slight_smile:

Cheers!
Arzumy

I'm storing files(images) outside document root. I have special action
for serving these files. It checks user permissions for file and sends
X-Sendfile header with filename and Apache serves the actual file to
user.

It does not block your ruby processes. If you are using Passenger,
than uploading large files are handled by Passenger and your script is
only called for processing, so it's not bocked either.

For Apache there is a module: http://tn123.ath.cx/mod_xsendfile/ ;
Nginx has this funtionality implemented.

M.

Thank you all for your responses. What I'm trying to achieve is
allowing users to post their photos
on the website and give them ability to search for photos of others.
Therefore, I'm dealing with large
number of files, not so much with large size of files.

Arzumy, you mentioned the Paperclip library. I've been looking into
integrating it with my Rails code
to do most of the image management. I installed the latest ImageMagick
version on Windows Vista, however I keep
getting problems. The ImageMagick installed correctly, the problem is
after I tried to submit my Rails form with
a .jpg or .gif photo it gives me the error:

"Photo C:/Users/.../AppData/Local/Temp/stream.1556.0 is not recognized
by the 'identify' command."

I read that I get this error message, because I need to install
dependency such as delegates for each file type
allowed to be processed, i.e. jpeg, by ImageMagick but all of the
articles that I came across they are not clear and
straight to the point how to install and configure those delegates on
Win Vista. I believe that you have
ImageMagick running on your machine and I was hoping that you can
direct me to a good resource
on how to get it working with Rails.

I would greatly appreciate any recommendations!

SS

Storing in the filesystem avoids database and app overhead, while also
allowing files to be moved to a different server if desired.

As for Imagemagick and rMagick and Rails, the IM part is simply to
install it and make sure your PATH includes IM's bin directory, as the
conversion process is pretty much just a system call to the `convert`
utility.

-eric