Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Problem accessing image from database

Posted on 2004-08-27
Medium Priority
Last Modified: 2010-04-06
Hi, I am trying to access an image stored in a database through ASP and JSP for ASP I am using msAccess database entering the image as a OLE Object and for Jsp I use a longblob datatype for both i use front end tools to insert the image in the record, i.e. access and MySQL-Front. How ever when retreiving the records I find that all the other columns show properly whereas the Image column returns the following:

MySQL            |      MSAccess
Image            |      Image            
[B@1603522       |      ?/
I would like to know how can I render the images in the resulting asp/jsp pages, do I have to store the image link and add that to the <img src=rs("image")> or is there another way to handle images? Moreover I would want the admins to update images, if possible, do i try copying files with local reference(client) to a specific folder on the server? Simply confused how to handle the image and what is the best data type in MS Access,SQL Server and MySql for images?
Question by:Ads
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +1
LVL 19

Assisted Solution

webwoman earned 300 total points
ID: 11913933
Don't put the IMAGE in the database. Just put the FILENAME in the database, upload the actual graphic, leave it as a graphic, and make a link to the graphic. Then you don't have any weird stuff in your database, you don't have to worry about binary files making your database 20 times bigger than it needs to be.
LVL 25

Expert Comment

by:James Rodgers
ID: 11915348
web woman is correct, once an image is placed inside an Access db there is a 'wrapper' placed around the image and you cannot extract the image in any way, except within the actual database for display on a form or report. Store the images in a separate folder on the server and store the file name in the db, as per webwoman's suggestion,and reference the file by path/name in the source of the img tag.

Expert Comment

ID: 11916148
I build a separate image display program where I feed the keys for my database.

sID = Request("ID")
sSql = "SELECT * FROM Images WHERE ID=" & sID
Set oRS = oConn.Execute(sSql)

Response.ContentType = oRS("ContentType") ' image/gif or image/jpg
Response.BinaryWrite oRS("ImageStore")
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 11923399
I tried doing that  here is an example of what i want ( this one works on intranet but not on the internet)
  Dim fsoObject
  Dim filObject
  pth = request.form("Image")
  Set fsoObject = CreateObject("Scripting.FileSystemObject")
  Set filObject = fsoObject.GetFile(pth)
  temp = Server.MapPath("images")
  filObject.Copy temp & "\",True
  Response.write("<br><hr>" & pth & " copied successfully!<br><hr>")

<form action="filecopy.asp" method="post">
<input type="File" name="Image" Accept="jpg/gif">
<input type="Submit" value="Submit">
<br> Please make sure the file you choose should be in a public folder and not have restrictive permission set on it.

The point being the admin should be able to upload the images to a folder on the webserver if I want this to work i could use a direct link but that way if the no of images increase it becomes pointless using asp. hence i wanted to use imags from database :-)
BTW quintsystems  I didnt quite understand what you meant by a separate program? do ya mean some kind of controls? pls, pls, give me some suggestions ....

Expert Comment

ID: 11930128
First, I assumed that you already had the image in the database and were trying to get it back out.  In a web page, you would display the image by making the separate program (code given before) to be the source in the image tag:

Response.Write "<img src='ImageDBView2.asp?ID=" & sID & "'>" or for link to image
Response.Write "<A HREF='ImageDBView2.asp?ID=" & sID & "'>Image</A>"

To upload an image you must have a form like:
<FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="ImageDBUp2.asp">
<INPUT TYPE="file" size="40" MAXLENGTH="100" NAME="txtImageStore" VALUE="<%= sImageStore %>">

Let me know if you are interested in the actual upload code...There are free controls for that and a free non-control method.

Hope this helps.

Author Comment

ID: 11931268
I would like the admins to be able to change the images of employees, for that I am open to suggestion, at first I thought that adding the image to the database would be fine but as all of you seggest it is better to copy it in some folder and link it dynamically based on the record id however I can't expect the local admins to ftp the web server  each time they want to update the images, I am open to using a free control if u can suggest one. Thanks a lot for helping promptly :-)

Accepted Solution

quintsystems earned 450 total points
ID: 11932343
Here is a link to a page with the free non-component method.

Galaxy Upload I think is the free component for an alternative.  Not sure where I got it.


Author Comment

ID: 11942136
Ok, I will try it out give me a couple of days and i will get back.

Author Comment

ID: 11950035
Hi, I tried the script, its basically giving the same error as my script, its something to do with permission at the ISP's end I would definitely say that your implementaion is cleaner and better but seems to do the same job, however when I try to run it on the ISP's Webserver it throws the error. On my intranet both scripts seem to do the job. Any suggestions?

The error message is:

sFullFilePath = X:\myisp\mydomain.com\images\img1.gif

Microsoft VBScript runtime error '800a0046'

Permission denied

/ULFile.asp, line 64
LVL 19

Expert Comment

ID: 11950963
You CANNOT put a file outside of your web if you're using an ISP's space. They will most definitely NOT allow it. They may not even HAVE an X drive, and even if they do, they sure aren't going to give YOU access to it. That's NOT what you've paid for.

Expert Comment

ID: 11951329
Yea...I can't ignore the permission denied message.  I am not up on how to deal with that.  Anyone else out there that can deal with this?

Author Comment

ID: 11957669
I myself was surprised how their server even allowed my script to throw that error however I have changed the drive letter and folder name on which the have hosted my application before posting, well they were definitely paid to store files :-) ) jokes apart, do I go about asking users(in my case the local admin) to ftp the web server and put images and then code for retreiving it? I know this is tricky but I even know there might be just some workaround? Anybody?

Author Comment

ID: 11957693
BTW I am trying to access (write) a file on my WEB that is an image subdirectory! however the filesystem object is taking it as a local drive on the Web Server and that is causing the problems.
LVL 19

Expert Comment

ID: 11959381
It will take it as a local drive on the webserver -- it HAS to. That's the only way it can do it.

Use server variables to find out the physical drive letter/path to your web folders. Use that for writing the files.

Better yet, tell your ISP what you're attempting to do -- they will most likely set up a special folder for you with the right permissions. The permissions you have for ftp'ing files won't work for an anonymous user -- and ALL your uploads are going to be from anonymous users.

Author Comment

ID: 11972094
Hi today i tested a app that downloads and uploads files, deletes them on my ISP's web server. It does not use any controls I think you can check it out Its Wex Lite 2.1 I dont remember the exact URL but I think thats my solution. webwoman I dont think any ISP is going to do what you suggested even if they do they will charge good amount of money for things that can be otherwise done for free, quintsystems thanks a lot for atleast trying to be there, you too webwoman I think I'll split the points even though the answer was somewhere else. :-)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

610 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