473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

quicker/easier/more secure to put pictures in BLOB fields in mysql or in a directory?

I am researching the best place to put pictures. I have heard form both
sides and I'd like to know why one is better than the other.

Many thanks!
Jul 17 '05 #1
3 3125
On Wed, 18 Aug 2004 15:08:49 -0400, "NotGiven" <no****@nonegiven.net> wrote:
I am researching the best place to put pictures. I have heard form both
sides and I'd like to know why one is better than the other.


What are your requirements?

If you've heard from both sides, what did you think of both sides of the
argument, and what were the arguments you read?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
In article <yL***************@bignews4.bellsouth.net>, NotGiven wrote:
I am researching the best place to put pictures. I have heard form both
sides and I'd like to know why one is better than the other.

Many thanks!


Like all things, it depends on the goal.

Put images in database under strange circumstances like:

.. Want a uniform backup process, all data in one spot. A DBMS will
guarantee that data cannot be accessed via any other means. (If your app
is something like a revision control system and you want to ensure the
DBMS is the only access gateway.)

.. Want database features (Ie, if the image is deleted than so is
the row, can't delete the file and mess something else up)

A case for this would be images with certain attributes, if the
row were deleted, but not the file, you might have a file w/out
associated information. Chances are this won't be a big deal, and
could easily be dealt with in a cleanup script if it ever were a
problem.

.. Want to allow image uploads, but don't want to leave write perms
on directories, if writing to server filesystem is major no-no, for
instance maybe you want it all run from a CDROM.

.. Space is for some reason cheaper on database (IE: ISP doesn't charge
for mysql space)

.. The unlikely event that you want to search *within* the blob data,
and your DBMS supports this.

.. Need network access to the image, network filesystems won't work for your
case and mirroring is not an option.

.. You have space/database on very strange filesystem such as a mainframe,
the server cannot access the large amount of space available on
the mainframe via filesystem calls. To utilize the space, SQL might be
used.

.. Your boss or client thinks it's best arguing about why filesystems are
more practical fall on deaf ears. ``Hey I paid for this fancy-shmancy
database I'd like to see it used to it's "fullest potential"''

.. When co-operating with existing software is a requirement.

Example:

Your application is a web based version of a desktop networked
application. (Such as a member list with photos) the desktop
application (Client program) fetches all it's data over the wire
from/to the database, and cannot access URL's and such the way a web
browser does.

.. Your particular filesystem is a very poor implementation, prone to
fragmentation and the images change a lot.

.. You want to burn as much CPU and network resources as possible :-)

.. You sell database software and need to show it off.

===============

Reasons against it (and probably many many more):

.. Web server can retrieve image directly. This is a lot faster
for serving static content. With a DBMS, not only do you have to
write special code to send images out, you have to contact the
database for them, giving you more network traffic and making the
database work harder.

.. To use the same BLOB in 2 records, You'd have to create 2 tables, one
for attributes and one for blobs, then cross reference them with a
relation. If you stored just the filename, the same image can be used
with multiple records and only one table. This is handy for a "no
photo available" default image.

.. It's easier to access with system calls.

.. More visable, can be updated easier with conventional tools like ftp
etc..

.. It's a heck of a lot faster and much less wasteful of resources.

.. Don't have to worry about strange differences between DBMS
implementations. (Some databases will alter the data adding \n's
or in other ways distort binary data, making things difficult later
on.

.. It's generally easier to access a file in chunks, a BLOB may or
may not insist on giving it all to you in one fetch.

.. Other tools can process images directly instead of intermediate
extract-to-tmp-file -> process -> insert to database. (Using temp
files to alter working copies is always a good idea, but the same
can be done much easier and more effectively with filesystem calls.)

.. Other people who work on code later on won't scratch their heads
trying to figure out why.

.. It's generally a more standard practice.

.. Filesystems can often locate filenames a lot faster than a search in a
database. (You can still use the database to search other attributes
by using a filename, obviously)

.. More scalable, can move images over to web servers stripped down to
serve static content, freeing the PHP-capable web servers for other
things, database for other "database things".

.. You really don't need to store it in a DBMS, the only time to store an
image in DBMS land is when there is a genuine need for it.
The definitive answer is.... neither. The web has too many grahics as it
is. Text-only web pages are better, so you should just forget the whole
thing. :-)

TIP: Give preference to the filesystem version. With lots and lots
of images, spread them across several directories, the fileystem will
be able to locate the filenames much quicker that way. To select a
directory to store the image, hashing functions generally work good.

Storing hundreds to millions of files in 1 directory can make working
with them an incredible hassle. (Especially when it's time to increase
storage space)

Hope I covered them all. :-)

Jamie
--
http://www.geniegate.com Custom web programming
User Management Solutions Perl / PHP / Java / UNIX

Jul 17 '05 #3
Average_Joe wrote:
Storing hundreds to millions of files in 1 directory can make working
with them an incredible hassle. (Especially when it's time to increase
storage space)


Not if you use ReiserFS.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sarah Tanembaum | last post by:
I was wondering if it is possible to create a secure database system using RDBMS(MySQL, Oracle, SQL*Server, PostgreSQL etc) and web scripting/programming language(Perl, PHP, Ruby, Java, ASP, etc)...
2
by: NotGiven | last post by:
Please help me understand the big picture of allowing users to upload pictures and keep them separate and tied to their record in the database. I want the whole thing automated and I'm just...
0
by: AJ Shankar | last post by:
Hi, In the C API, is there any way to execute a query, store all the results, and somehow find the maximum realized width for each of the fields before fetching each row? Otherwise there is no...
3
by: Jim S. | last post by:
Hi guys, i have lots of data for products (with different categories) and pictures that i would need it entered into a database on the website. How would i go about doing so? i was thinking...
1
by: konsu | last post by:
Hello, I am planning to implement an image and movie library (e.g. a photoalbum), and one of the ways that I see to store image and movie files is to put them in to BLOB fields in an sql table....
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
2
by: pmz | last post by:
Dear Group, I'm connecting in C# with remote (BSD) MySQL server with ODBC Driver, and I'm trying to find the best sollution in such problem: As I've read on MySQL manual, they have suggested...
9
by: blessblessbless | last post by:
Hey guys, I am creating a code out of bits and pieces I found in somebody else's code, so I am not entirely sure how it behaves. <IMG SRC="picture.php?ID=1029&THUMB=yes"> picture.php: <?...
46
by: RAZZ | last post by:
Hello, Can anyone suggest me solution? I Need to manage different types of documents (doc,xls,ppt etc) in server. I have folder structure to maintain these documents in server. Say folder1 is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.