Jump to content

How to display ASCII binary jpeg data?


foxman

Recommended Posts

Hey,I have a database with records including a binary stored image, ASCII. I would like to display these images, all JPEG, on a .asp page.My code is:<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><html><head><link rel="stylesheet" type="text/css" href="stylesheet/style.css" /><title>Product Database</title></head><body><div class="content"> <% DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT itemcode, description, UserField_02, Usernumber_07, CostPriceStandard, SalesPackagePrice, picture FROM items WHERE Assortment=2" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn %><table width: 650%;> <% DO WHILE NOT rs.EOF %> <tr> <td><img src=images\logo\fox.jpg \></td> <td><center>Product informatie</center></td> <td><img src=images\logo\fox.jpg \></td> </tr> <tr> <td colSpan=3><center><h2><% Response.Write RS("itemcode") %> - <% Response.Write RS("description") %></h2></center></td> </tr> <tr> <td>Itemcode:</td><td><% Response.Write RS("itemcode") %></td> </tr> <tr> <td>Description:</td><td><% Response.Write RS("description") %></td> </tr> <tr> <td>Box size:</td><td><% Response.Write RS("UserField_02") %></td> </tr> <tr> <td>Weight:</td><td><% Response.Write RS("Usernumber_07") %></td> </tr> <tr> <td> <% Response.ContentType = "image/jpeg" Response.BinaryWrite RS("Picture").GetChunk(Rs("Picture").ActualSize) %> </td> </tr> <tr> <td class="high" colSpan=3><hr></td> </tr><%rs.MoveNextLoop%> </body></table></div><%rs.CloseSet rs = NothingConn.CloseSet Conn = Nothing%></body></html>This results in this error:ADODB.Field error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /products/index.asp, line 55 What am I doing wrong? Thanks in advance!

Link to comment
Share on other sites

Binary and ASCII are mutually exclusive. Data can either be binary, or ASCII, but not both. Also, by my count line 55 is a line that only has <tr> on it, what code is causing that error?
Thank you for your answer. Sorry for the line mistake; in the example I gave, I deleted some enters that didn't belong there. Exactly the code above, the error is on line 54: Response.BinaryWrite RS("Picture").GetChunk(Rs("Picture").ActualSize)The codes in the column picture lookes like this:0xFFD8FFE000104A46494600010101004800480000FFE12F5645786966000049492A000800000012000E01020020000000E60000000F010200050000000601000010010200080000000C01000012010300010000000100D8DA1A01050001000000140100001B010500010000001C01000028010300010000000200E2E2320102Does this make it more clear?
Link to comment
Share on other sites

That's just binary data, in hex format. Why are you using GetChunk if you're getting everything? Why don't you just write out the field instead of getting part of (all of) it?
Hey, If I do this: <tr> <td> <% Response.ContentType = "image/jpeg" Response.BinaryWrite RS("Picture") %> </td> </tr>I get the following error:Response object error 'ASP 0106 : 80020005' Type Mismatch /products/index.asp, line 54 An unhandled data type was encountered. The first record has no image filled in, so it gives this problem.But if I change my sql query so it only gets a record with a image, I get a huge strangly looking code. If I copy it and past it in Word, I get 199 pages, Arial 12pt. This is the first part of it:ÿØÿàJFIFHHÿá/VExifII* æ ØÚ(ââ2$À¾i‡T¤°²¤×Ú¤áߤãá¤áà ¤ÔÒ ¤¾¼¥Ä8® SONYDSC-P43HH2007:01:18 17:24:23PrintIM0250š‚V‚^"ˆJÍ'ˆd0220fz‘‘Ž’ –’ž’Ã’ýã ’­ ’¦ 0100 ¼q £È`2£g{ 2007:01:18 17:24:232007:01:18 17:24:23 /2 9+,2ÜÖ:B(¬‰2J^ð+SONYDSC-P43HH2007:01:18 17:24:23ÿØÿÛ„ ÿÄ¢ }!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùú w!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÀx !ÿÚ ?ùªÃJˆ& ¦+¶µÓ@¿¹{é_„{$õ?U©^]YÑÛhˆvÏó®¢ÓD»Ö·…sʬŽž×B@Þµ&ƒJÒ£Ž]RûMÒãoº×S¤A¾…ˆÍuC ÛÓsײ»gOa¥Ã<\@`žRXØ2¸õ 85»‹ž‘^jÕ{º­ërÉÐÕ‘¿wƒžõh[å5¢¥ÜÎU_q?°Âç0äý*Ñî€âbOµo©—6‰’sŸëU“A à9ëëS*]X{W܃]ðãA ù°mlgÖ¼£QÐÈ,Jekžù•ËUVyö©¢²b%纎ˉG'ñ¦é½MaUõg}¥)-û¯—8é\.­¦*e1ŽsŒçÞ¹êAîvÒªï¹õ†§´k½°Òó·Or}+ºzœu*7©×ÙiŠäzûV½óèþÒïµÍSÓ´]Ö .n®®æEH¥™Ù˜ã}k®4NwWv~ßÿÁG¾øÏ^ðÇ€þ^k.ñ&­4°ý²m2H!° É’A0RT™v†,àUŽ?µGÀ߃ž½—Ç—^9ø‰,dÀøó^âQÁê¬pª¡NÓ÷@Üßke¯ âq1¼¯Ë~½[üúÙkn‡Î㪬eXáéIÆ 9NV½’²Ñiwweª¼®·Q¹:óÚ¹ëCFÊRfwŠôÕgòü¶ù>^ExÆ«¥(m¬0Ìx÷5j^æ¥){×8-KE<þìߊóíSF7È9ö«•ÔÑLóÝKE*XmÀ9Îk‚Õt…h¥Êá°yõ®yѺ:)Ôzw>œÓ¬%p{û×}§iã Çÿ^»! îa)_SæïÚ»öÄøWû$øKíþ#‘|C㛵dÒ:þ×??iÏÙj¿õYu{DǦxrËzi–*NB$ þºCÞI2O¦8¯¡ÈðÊmÖjéh½z¿ÓÖ燜âd¿tž¯Wýyîwß°f•wwû@ÜßjK9´Û ãò†Ò;`të€sé־ߵøuc⯈¾ñ׉üK.“qgwê#Jös" %#F׶FI ‘_sW+©‰Ã¥N|’Rºv涖Õ]_FúùžKÄ4p8ÉËKÛRœ9egÓ—2jI;5(§³¾ÝNëö™ðÂûÿ‡?´„Ofcourse, this is not the image I imagened!
Link to comment
Share on other sites

That is the image, that is the binary code of the image being interpreted as ASCII text. But you're displaying the image wrong. You're doing this:<td><% Response.ContentType = "image/jpeg"Response.BinaryWrite RS("Picture")%></td>So you write a <td>, and right inside the td you try to send a new content-type header (which applies to the entire HTML page, not just what is in the td), and then just spit out all the code. That's why it's showing up as ASCII text, because it's in an ASCII document. You can't start an ASCII document (an HTML page) and right in the middle of it spit out some binary data. The content-type of that HTML page says that it is text/html, you can't change the content type in the middle of everything and try to output something else, it just doesn't work that way. Every document has exactly one content type, no more and no less. You need to write a new ASP script that only outputs the image, and link to that script in the HTML page. So your td would look something like this:<td><img src="get_picture.asp?id=10"></td>The get_picture.asp page would get the ID that was passed to it, look up that record in the database, and spit out the content-type header and the binary data, then end the response.

Link to comment
Share on other sites

What do you mean? If you're talking about a variable like this:get_picture.asp?id=10You would retrieve the value using Request.Querystring("id").
Well, I don't know how to get my itemcode send to the address of the image.aspThis is what I have in my index.asp<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><html><head><link rel="stylesheet" type="text/css" href="stylesheet/style.css" /><title>Title</title></head><body><div class="top"><p>Formulier keuze</p></div><div class="content"> <% DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT itemcode, description, UserField_02, Usernumber_07, CostPriceStandard, SalesPackagePrice FROM items WHERE Assortment=2" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn %><table width: 100%;> <% DO WHILE NOT rs.EOF %> <tr> <td><img src=images\logo\fox.jpg \></td> <td>Product informatie</td> <td><img src=images\logo\fox.jpg \></td> </tr> <tr> <td colSpan=3><center><h2><% Response.Write RS("itemcode") %> - <% Response.Write RS("description") %></h2></center></td> </tr> <tr> <td>Itemcode:</td><td><% Response.Write RS("itemcode") %></td> </tr> <tr> <td>Description:</td><td><% Response.Write RS("description") %></td> </tr> <tr> <td>Box size:</td><td><% Response.Write RS("UserField_02") %></td> </tr> <tr> <td>Weight:</td><td><% Response.Write RS("Usernumber_07") %></td> </tr> <tr> <td> <img src=image.asp?itemcode=????Here I need the itemcode, for every result again and again????> </td> </tr> <tr> <td class="high" colSpan=3><hr></td> </tr><%rs.MoveNextLoop%> </body></table></div><%rs.CloseSet rs = NothingConn.CloseSet Conn = Nothing%></body></html>In my image.asp i have this:<% itemcode= Request.Querystring("itemcode") DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT picture FROM items WHERE Itemcode=" & itemcode &" " DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn %><% Response.ContentType = "image/jpeg"Response.BinaryWrite RS("Picture")%>So how do I give my image.asp the right itemcode?
Link to comment
Share on other sites

After more testing, I have this in my image.asp:<% DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT picture FROM items WHERE Itemcode='request.querystring("itemcode")'" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn %><% Response.ContentType = "image/jpeg"Response.BinaryWrite RS("Picture")%><%rs.CloseSet rs = NothingConn.CloseSet Conn = Nothing%>Having this url: http://fs-01/products/image.asp?itemcode=0020007Unfortunatily I get a HTTP 500 error. What am I doing wrong?

Link to comment
Share on other sites

So how do I give my image.asp the right itemcode?
Write it from the recordset, the same way you're doing it with everything else.
Unfortunatily I get a HTTP 500 error.
I get a 404 error:
Not FoundThe requested URL /products/image.asp was not found on this server.
You'll also want to remove the extra line breaks in the image.asp script, here:rs.Open sql, conn %><% Response.ContentType = "image/jpeg"Response.BinaryWrite RS("Picture")%><%rs.CloseThere's no reason to end the ASP script and immediately start it again, just remove those spaces. You're trying to output binary image data, and when you have those spaces you're putting an ASCII line break there.
Link to comment
Share on other sites

Hey,Sorry, but if I use the code below. I always get No Image.If I replace the red part with a code that is in my DB, I do get my image.Note, because my itemcode is both letters and numbers i have to use 'xxx'So my sql query: sql ="SELECT picture FROM items WHERE Itemcode=' & ID & '" is not correct.I have been playing with it and searching for a while now, but I cant figure it out.<% dim ID ID=request.querystring("ID") DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT picture FROM items WHERE Itemcode=' & ID & '" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn if not rs.eof then Response.ContentType = "image/jpeg" Response.BinaryWrite RS("Picture") else response.write"No Image." end if rs.Close Set rs = Nothing Conn.Close Set Conn = Nothing%>

Link to comment
Share on other sites

Hey,I finally figured it out. My image query looks like this now:sql ="SELECT picture FROM items WHERE Itemcode = '" & itemcode & "'"Just for the Knowledge Base, this is my final sollution:The index.asp:<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%><html><head><link rel="stylesheet" type="text/css" href="stylesheet/style.css" /><title>Product Database</title></head><body><div class="content"> <% dim ITEM ITEM=request.querystring("ITEM") DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT Items.ItemCode, Items.Description_0, Items.Description_1, Items.Description_2, Items.UserField_02, Items.Usernumber_07, Items.Class_01, ItemAccounts.crdnr, cicmpy.cmp_name, ItemAccounts.ItemCodeAccount, Itemclasses.Description FROM Items LEFT JOIN ItemAccounts ON Items.Itemcode=ItemAccounts.ItemCode AND Items.lev_crdnr=ItemAccounts.crdnr AND Items.Itemcode IS NOT NULL AND ItemAccounts.ItemCode IS NOT NULL AND Items.lev_crdnr IS NOT NULL AND ItemAccounts.crdnr IS NOT NULL LEFT JOIN cicmpy ON cicmpy.crdnr = ItemAccounts.crdnr AND cicmpy.crdnr IS NOT NULL AND ItemAccounts.crdnr IS NOT NULL LEFT JOIN ItemClasses ON Items.Class_01=ItemClasses.ItemClassCode AND ItemClasses.ClassId=1 WHERE Items.itemcode = '" & ITEM & "'" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn %><table width: 100%;> <% DO WHILE NOT rs.EOF %> <tr> <td align="left"><img src=images\logo\fox.jpg \></td> <td align="center">Product informatie</td> <td align="right"><img src=images\logo\fox.jpg \></td> </tr> <tr> <td colSpan=3><center><h2><% Response.Write RS("Itemcode") %> - <% Response.Write RS("Description_0") %></h2></center></td> </tr> <tr> <td colspan=3> <img src=image.asp?itemcode=<% Response.Write RS("ItemCode") %> width="648px" height="486px"> </td> </tr> <tr> <td colspan=3 height="20px"></td> </tr> <tr> <td>Itemcode:</td> <td><% Response.Write RS("ItemCode") %></td> </tr> <tr> <td>Description NL:</td> <td><% Response.Write RS("Description_0") %></td> </tr> <tr> <td>Description EN:</td> <td><% Response.Write RS("Description_1") %></td> </tr> <tr> <td>Description CS:</td> <td><% Response.Write RS("Description_2") %></td> </tr> <tr> <td colspan=3 height="15px"></td> </tr> <tr> <td>Box size:</td> <td><% Response.Write RS("UserField_02") %> cm</td> </tr> <tr> <td>Weight:</td> <td><% Response.Write RS("Usernumber_07") %> kg</td> </tr> <tr> <td colspan=3 height="15px"></td> </tr> <tr> <td>Main Customer:</td> <td><% Response.Write RS("Description") %></td> </tr> <tr> <td colspan=3 height="15px"></td> </tr> <tr> <td>Supplier:</td> <td><% Response.Write RS("crdnr") %> | <% Response.Write RS("cmp_name") %></td> </tr> <tr> <td>Suppliercode:</td> <td><% Response.Write RS("ItemCodeAccount") %></td> </tr> <tr> <td class="high" colSpan=3><hr></td> </tr><%rs.MoveNextLoop%> </body></table></div><%' Don't forget to close your connection after you display your data.rs.CloseSet rs = NothingConn.CloseSet Conn = Nothing%></body></html>The image.asp:<% dim itemcode itemcode=request.querystring("itemcode") DIM conn set conn=Server.CreateObject("ADODB.Connection") conn.Open "111" DIM sql sql ="SELECT picture FROM items WHERE Itemcode = '" & itemcode & "'" DIM rs set rs=Server.CreateObject("ADODB.recordset") rs.Open sql, conn if not rs.eof then Response.ContentType = "image/jpeg" Response.BinaryWrite RS("Picture") else response.write"No Image." end if rs.Close Set rs = Nothing Conn.Close Set Conn = Nothing%>As you can see, my sql query changed a lot, thats because I wanted more information. I know it's all basic, but if I make mistakes or stuff can be done better or easyer, I would like to know!I use a css for the stylesheet.Anyway, for now loads of thanks justsomeguy! Your help was very welcome and good!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...