Best practice to store images in database ??? BLOB or URL based

[size="4"]Hi All,

I badly wanted to know the the best practice to store images in database.

there are two options,

1/ store them as blob types.

2/ save it in a folder and insert the url of the image stored location in database.

please if can anyone clear me on this by giving some examples it will be great.

thanks alot in advance. [/size]

BLOB ::)

why your telling blob ? can you please elaborate further. tnx

its more secure…

It depends on how you have structured your application, on some applications where you have several places to access the image, the querying will ofcourse slow down compared to directly accessing the file from the file system. Then there’s another issue/overhead of writing additional code to extract the images and display in a meaningful way.

Storing paths and using them is what I prefer. But you can go with DB too :)

There is nothing like DB is the best or File system is the best - place to store images. It just depends on how you are designing the structure of your application.

but from performance side. i think this way is not good. let me know what you think of this.

Storing them as BLOB will result in huge databases, I almost always avoid using BLOB.

tnx

tnx

I also almost always use the URL method.

It keeps the database size small, number of queries few and size of query results small,

which all means the database performs faster.

I let the web-server handle all the filesystem I/O.

This is the most stupid thing i ever heard for a while now, i would like to see you handling a database with 1000 big images(> 5 mb) and also i would like to see you manipulating the images (like resize or watermark), all of these in a website that gets >= 10000 hits/day.

Security ? How is more secure to save into database than using the file system ?

Don’t learn people do stupid things.

Aside from what’s already mentioned, going with the FS/URL enables better site performance with misc web server performance boost systems (caching, different web server for certain file types (.jpg etc)) and also supports CDN usage when/if applicable. Although, I must note that “premature optimization is the root of all evil”… .

I can only add that when you’re working on something that should be stateless (a web-application that can easily run among multiple webservers), than it could be easy to separate any variable data from the application directories and thus save it in the database. We choose to save images in Amazon’s S3, which also enables you to separate it from the web application itself.

I agree with the majority above. I always store images on the file system and store some sort of reference to them in the database. If you’re concerned about preventing unauthorised users from accessing your images, you can always store them in a protected directory and use an action to write their contents out when requested by authorised users.

Hey all of you guys seem like the expert on Images. Well, then can you help me solve this stupid problem I’m having with images.

http://www.yiiframework.com/forum/index.php/topic/35093-image-display/

Must be really funny to store a few thousand huge images in a database and replicate them on several nodes. I guess if you have enough load you don’t exceed the cpu or ram resources of the server, but simply its bandwidth ;D

Regards,

I am using Amazon S3 to store the images too.

May you need to take a look at this too : YiiAWS

You can store the images in folder and save the path(the folder path when image saved) to database. So we can display that image easily.

Fatal error: Call to a member function saveAs() on a non-object

I fade up with this message please help me.

Thanks in advance