Solved

Problem accessing image from database

Posted on 2004-08-27
15
178 Views
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?
0
Comment
Question by:Ads
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 19

Assisted Solution

by:webwoman
webwoman earned 100 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.
0
 
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.
0
 
LVL 1

Expert Comment

by:quintsystems
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")
0
 

Author Comment

by:Ads
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>")

%>
<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 ....
0
 
LVL 1

Expert Comment

by:quintsystems
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.
0
 

Author Comment

by:Ads
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 :-)
0
 
LVL 1

Accepted Solution

by:
quintsystems earned 150 total points
ID: 11932343
Here is a link to a page with the free non-component method.
http://www.cymbala.com/Greg/HowToUpload.htm

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

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

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

Author Comment

by:Ads
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
0
 
LVL 19

Expert Comment

by:webwoman
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.
0
 
LVL 1

Expert Comment

by:quintsystems
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?
0
 

Author Comment

by:Ads
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?
0
 

Author Comment

by:Ads
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.
0
 
LVL 19

Expert Comment

by:webwoman
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.
0
 

Author Comment

by:Ads
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. :-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

13 Experts available now in Live!

Get 1:1 Help Now