Ads
asked on
Problem accessing image from database
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?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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")
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")
ASKER
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.Fi leSystemOb ject")
Set filObject = fsoObject.GetFile(pth)
temp = Server.MapPath("images")
filObject.Copy temp & "\",True
Response.write("<br><hr>" & pth & " copied successfully!<br><hr>")
%>
<html>
<body>
<p>
<hr>
<form action="filecopy.asp" method="post">
<input type="File" name="Image" Accept="jpg/gif">
<input type="Submit" value="Submit">
</Form>
<br> Please make sure the file you choose should be in a public folder and not have restrictive permission set on it.
<hr>
</p>
</body>
</html>
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 ....
<%
Dim fsoObject
Dim filObject
pth = request.form("Image")
Set fsoObject = CreateObject("Scripting.Fi
Set filObject = fsoObject.GetFile(pth)
temp = Server.MapPath("images")
filObject.Copy temp & "\",True
Response.write("<br><hr>" & pth & " copied successfully!<br><hr>")
%>
<html>
<body>
<p>
<hr>
<form action="filecopy.asp" method="post">
<input type="File" name="Image" Accept="jpg/gif">
<input type="Submit" value="Submit">
</Form>
<br> Please make sure the file you choose should be in a public folder and not have restrictive permission set on it.
<hr>
</p>
</body>
</html>
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 ....
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-da ta" 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.
Response.Write "<img src='ImageDBView2.asp?ID="
Response.Write "<A HREF='ImageDBView2.asp?ID=
To upload an image you must have a form like:
<FORM METHOD="Post" ENCTYPE="multipart/form-da
<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.
ASKER
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 :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I will try it out give me a couple of days and i will get back.
ASKER
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\imag es\img1.gi f
Microsoft VBScript runtime error '800a0046'
Permission denied
/ULFile.asp, line 64
The error message is:
sFullFilePath = X:\myisp\mydomain.com\imag
Microsoft VBScript runtime error '800a0046'
Permission denied
/ULFile.asp, line 64
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.
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?
ASKER
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?
ASKER
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.
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.
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.
ASKER
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. :-)