Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a Decoded JPEG Image

Status
Not open for further replies.

gregarican

IS-IT--Management
Jan 31, 2002
469
US
I have a SQL database table housing Base64 encoded JPEG images. To review these images I have created an ASP to decode the image into its binary form and then display it. I pass a couple of QueryStrings into the ASP to narrow down the SQL query to a specific image. Then I am passing the results back to another ASP that's referring to it as an <IMG SRC>.

From that I can tell the Base64Decode VBScript function is doing its job. Otherwise there are custom error codes that would be returned if the decoding failed. But instead of an image displaying there is just a broken link. Here's a snippet of the code below, not including the Base64Decode function since it is working.

Any suggestions as to what I'm doing wrong? I've googled for about an hour and haven't hit an exact answer...

'Step 1: Read in the querystring
iVendor= Request.QueryString("made_by")
iStyleNo=Request.QueryString("style_num")

'Step 2: grab the picture from the database
Dim Connection, RS, strSQL, imageFile
strSQL = "SELECT stock_image as stock_image FROM theBox WHERE made_by = '" & iVendor & "' and style_num = '" & iStyleNo & "' "


CONN_STRING = "Provider=SQLOLEDB;Data Source=myServer;Initial Catalog=theBox;"
CONN_USER = "username"
CONN_PASS = "password"

Set Connection = Server.CreateObject("ADODB.Connection")
Set Cmd = Server.CreateObject("ADODB.Command")
Set RS = Server.CreateObject("ADODB.Recordset")

RS.CursorType = adOpenForwardOnly
RS.LockType = adLockOptimistic

Connection.Open CONN_STRING, CONN_USER, CONN_PASS
Set Cmd.ActiveConnection = Connection

Cmd.CommandText = strSQL
Cmd.CommandType = adCmdText

RS.Open Cmd

'Step 3: Convert the image file from Base64 to JPEG
imageFile = Base64Decode(RS("stock_image"))

'Step 4: Set the ContentType to image/jpeg
Response.ContentType = "image/jpeg"

'Step 5: Use Response.BinaryWrite to output the image
Response.BinaryWrite imageFile

'Clean up...
Response.End
RS.Close
RS = Nothing
Connection.Close
Connection = Nothing
 
I would try two more things to see if you get better results:
1) Instead of decoding, just write the data to see what happens
2) Try a different record if you have done all your tests on the same record.

Something that may be important is what application is doing the base64 encode before putting it into the database. If you have access to this I would suggest doing an encode with that application and then change your application to decode to a file using FSO. Then try to compare the to files to make sure the decode is making the same assumptions about bit order, etc as the encode.

-T

 
Thanks for the tips. I think I have ruled out the encoding/decoding portion of things. Even replacing the Base64Decode function with a direct reference to a JPG file in the IIS 6.0 site directory results in the same broken link icon displating as oppposed to the picture. I'll look deeper Monday. Thanks again!
 
Interesting, that almost sounds like it's a problem with the page you have the img tag embedded in rather than this once. How about posting up the img tag and your directory structure? maybe you've overlooked something a fresh set of eyes would notice.

-T

 
Appreciate all of the assistance. Since I was in a time crunch I resorted to using some Ruby scripting to accomplish what I was looking to do. Thanks anyway!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top