Store image as blob or as file pointers

Hi
This is a general implementation question…I am using different
company logos in my application…And I am familiar with saving these
images as file pointers in the DB…What I am asking is if I directly
save this images to DB as blob(for example image data type in postgres)
what are the advantages and is there any disadvantage in terms of
performance?

Thanks in advance
Sijo

This is a general implementation question…I am using different
company logos in my application…And I am familiar with saving these
images as file pointers in the DB…What I am asking is if I directly
save this images to DB as blob(for example image data type in
postgres)
what are the advantages and is there any disadvantage in terms of
performance?

If you google you’ll find lots of discussion about this. I’ve done it
both ways for different reasons.

The most recent was user avatars. On average they were under 4kb in
size. I decided keeping them in the database made my life easier. On
render I would then cache them disk and sweep them when necessary.

Best of both worlds.

It also meant I could add front end servers as necessary and not have
to worry about syncing images on disk around.

You need to decide how many images, how large, etc…

-philip

Mine preferred solution is media files stored on file system
It is somehow more flexible solution.
The image in database have tendency to be part of select statement
even if not required, particularly on project with bunch of unexpired
developers or new team members.

Every particular solution has pros and cons and it’s is about your
project requirements and future plans.

Mine preferred solution is media files stored on file system
It is somehow more flexible solution.
The image in database have tendency to be part of select statement
even if not required, particularly on project with bunch of unexpired
developers or new team members.

Excellent point! I should have mentioned that when I did store mine
in the database it went into it’s own “avatars” table and model. So
normal queries for users never touched it unless I explicitly asked
for it.

But you’re absolutely right about that being an issue.

Hi
thanks for all the reply…Actually I was planning to store only some
logos maximum 20, of size average 10 kb

Sijo

For 20 logos, 10kb size, I would recommend storing them in the
database and caching them as they are rendered.

Unless you are using a distributed cache, though, I don’t know how
uploading a new avatar on (say) host 1 and then clearing it from host
2’s cache will work though. I would be tempted to
cache them for a maximum time as well and refresh them as needed.

I have one model in most of my apps that use images. It only has an
ID, image format, image size, and image data. I don’t store avatars
with the user table, for instance. This image model is only used in
two cases: one, when rendering the HTML link info, and again when
rendering the actual image data. I don’t fetch the image data when
finding the size.

If you have a local cache, you could write the image data when
retrieving the size as well, since it’s pretty likely the request will
come soon.

–Michael

On Sat, Jul 26, 2008 at 4:00 AM, Sijo Kg