Macros and Programming


CardboxForumsMacros and Programming > "WritetoBytes"


How to make WritetoBytes work

Current user: [none]
Register / Log In · Help

Posted By Post

Charles Welling

5-Aug-2014 19:29

I have a large database on the Internet using Cardbox and ASP with all images as external files, which was the best option for this application. But now I'm going to use Cardbox as a CMS as well, which is a much smaller application with text and images changing on a daily basis. In that case it would be easier to load the images into the database and use WritetoBytes to make them visible to the user. I've tried the example, exactly as it reads in the help file, but somehow I can't make it work correctly. Looking for help on the Internet gave me the same example, so I assume that that's correct.

What it does do, is that it shows the image as a whole lot of characters. The bytes seem to be dumped onto the screen and the image does not show as an image. I've tested with several browsers and the results were all the same.

Does anyone know what might be wrong?
Any help highly appreciated!


5-Aug-2014 20:36

Perhaps you need to add:
Response.ContentType = "image/jpeg"


5-Aug-2014 20:46

Just saw this was is in the help...
Did you perhaps use b.e. cbxImageRecodeAsJPEG in stead of contants (numbers)?
In ASP you only can use constants (or first declare them of course)

Charles Welling

5-Aug-2014 22:04

Thanks for your quick response, Bert, but yes, I did use the constants.

set img = record.images.item(1) >>> "record" is previously set to a single record from a search result
arr = img.WriteToBytes(16,0,0,80) >>> always write as jpeg, no resize, quality 80
Response.ContentType = "image/jpeg"
Response.BinaryWrite arr

What I get is not the page as it should look, because the browser cannot recognise the file as valid html. All I see is the html itself and where the image should appear, I see:

%# , #&')*)-0-(0%()(��C

(((((((((((((((((((((((((((((((((((((((((((((((((((�� � > " ��








and a lot more of this!

I don't know if I'm overlooking or omitting something very obvious. As far as I can see Cardbox indeed writes the image (I tried several ones), but it looks as if they might be corrupted in the process.


5-Aug-2014 22:43

Nice image... ;-)

I wrote for the image a separate script (kind of function).
In images.asp the right record(image) is selected (using a querystring) and in that script you use WriteToBytes.

In the script that produces the html page I solved writing the image like this:
rec = "<img src=""image.asp? [[here querystring parameters for selecting the record]]]"" & " border=""0"" class=""imgg"")><br>"

On this way the selected image is showed in any browser.

Charles Welling

6-Aug-2014 08:24

Thanks Bert, that did it. Still, it's strange that the example, which can be found on all sites that host tutorials on ASP, doesn't work. It's obvious that the solution lies in telling the browser that the array is an image by using "img src=", but even then it really needs a file, i.e. the "images.asp" you used.

arr = img.WritetoBytes(16,0,0,80)
response.write("<img src=" & arr & ">")

which is basically the same as the asp file only returns arr, didn't work either.


7-Aug-2014 08:50

Of course it works ;-)
As far as I know every image showed in a browser always is written in cache. Nice is that the stored Cardbox image not is written out of from Cardox on the server somewhere, but only at client side. That was the meaning of this Cardbox command that was added for ASP applications.

Quick Reply

Please log in or register before trying to post a reply.

© 2010 Cardbox Software Limited   Home