gregarican
IS-IT--Management
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
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