473,769 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3145
On Wed, 18 Aug 2004 15:08:49 -0400, "NotGiven" <no****@nonegiv en.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.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
In article <yL************ ***@bignews4.be llsouth.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
3136
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) combination? I have the following in mind: I wanted to store all my( and my brothers and sisters) important document information such as birth certificate, SSN, passport number, travel documents, insurance(car, home, etc) document, and other...
2
2658
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 trying to get my arms around what all is entailed. Each user will upload about 20 - 100 pictures and each will be related to a different database record. I see the process in general as this:
0
623
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 way to efficiently retrieve string data. The best you can do is either allocate a static buffer of 64K (max size for a blob) or some smaller buffer that may not actually be able to contain all the data.
3
2021
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 about an excel sheet with each category as a sheet but i have no idea what to do about the pictures that will go with each product, (since i would not want the pictures in the mysql database.) any ideas?
1
3010
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. I would greatly appreciate any information as to how this method compares with simply storing the images and the movies as plain files on disk. Does MySQL add a lot of overhead when retrieving images from BLOBs compared to reading the files from...
7
11484
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 convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
2
9001
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 table design including the BLOB-Fieldtype size in UInt64, where they've stored, while inserting, the size of inserted BLOB data. But in the matter of fact, I'm interested if it's necessary to include in table this integer field? Is there any way...
9
2455
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: <? Header( "Content-type: image/jpg"); $linkID = mysql_connect("host", "user", "password");
46
2173
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 having all doc files; folder2 is having all xls files and so on. Now these documents should not be able to get access through the url
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.