Stored procedure to convert blob to image file

Posted on 2007-07-22
Last Modified: 2008-09-19
Windows 2003 Server running IIS and SQL Express 2005

I have clients who send records containing some images to my SQL server. (Each record can contain upto 10 image fields)  Although using  blobs to contain images on their client software is a good idea, I would prefer to use the local file system for the purpose of displaying the images from IIS

I am hoping to create a trigger on the SQL Server so as a record is updated or added, the blob is saved to the local file system as an image file. It then can be access by IIS and displayed to a users browser.

I am not an expert on SQL Server, but I figured a stored procedure could be called by the trigger ...

Is this possible from withing a stored procedure?

Question by:bewildered
    LVL 4

    Expert Comment

    "Although using  blobs to contain images on their client software is a good idea"
    Create a root directory called, say, D:\ClientImages
    Under it have a folder for each client. When the client 5 uploads an image mypic.jpg, place it into D:\ClientImages\5\mypic.jpg
    If you don't let them create folders, but only to place the images in one directory, your table will look like:
    (clientID, fileName) with the values(5,'mypic.jpg')
    That was the file is always on the file system, you lower the storage costs on the DB tremendously and everyone is happy

    Author Comment


    A Data entry person adds records to an access db that include images. The access DB is then copied to one or more laptops for sales staff to go on the road with.

    This is a simple and clean method to make the data available to staff who do not have an internet connection available while travelling.

    The Data entry person also uploads the records from the central access DB to the SQL server. At this point I would like to create the individual image files for use on the website.

    Cheers Tony
    LVL 4

    Accepted Solution

    How many records they are going to have?
    Access is known for bloating as it's being used. Storing images in Access is sure going to push it towards the 2 Gb file size limit ( ) and, believe me, you will start getting problems way before it reaches 2 Gb.

    I guess if you're only use Access as a way to view the files and never to modify it, it can fly. But there's nothing that forces you to store images in the central database as opposed to file system (which is what you want anyway).

    I'm not trying to be overly critical, just the database is a bad place for storing images - it doesn't give pretty much any benefits, and causes you troubles when you try to display them. So rather than work around a bad design by writing triggers and exporting files to the disk, why not change the bad design and store the files on disk to begin with?

    Author Comment

    Thanks for the input,

    I think I will abandon the question ...

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now