Solved

Response.BinaryWrite not working.

Posted on 2004-09-17
5
422 Views
Last Modified: 2008-03-03
i am trying to output an image using response.binarywrite.
the following is teh code i am using:

Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream")
 
  'Open a GIF file
  objStream.Type = adTypeBinary
  objStream.Open
  objStream.LoadFromFile "C:\Image.png"
 
  'Output the contents of the stream object
  Response.ContentType = "image/png"
  Response.BinaryWrite objStream.Read
 
  'Clean up....
  objStream.Close
  Set objStream = Nothing

instead of outputting an image, it just outputs a string of byte (i think) data. eg. ‰PNG  IHDRg&™Ôº IDATxœì½\÷ÿO¿µßÚ«í¥={1­ÉÙœ—šži½×r—œ1­Müzš#Õ¼r•Zs¡§gMj¯ä§•‡Õ”$Ö˜„FkÕ« *âWAþ‰ŠBåËÿ™ß볟evvfvvfv—¿ï烇îÎÎοù¼>ïÏçý'D ‚ B!ƒ}A1l Õ$‚ ½0Õ´ÙzbcKð·eK^k¬m·÷ΟŸ[Yi¨#”c±Ôð£µZ¯ä~.b§ë֝Îξ®½f\\iTTö¶m•s`横jÃ¥¦ÖI64ta¡t VÀÎ?Z¶,W€¿ññŸà4qÏ8÷Äõ naM¼

does anyone know what is happening??
0
Comment
Question by:hkdcde
  • 3
5 Comments
 
LVL 15

Expert Comment

by:joeposter649
ID: 12084886
Try Response.ContentType = "application/octet-stream" or Response.ContentType = "image/gif".
0
 
LVL 19

Expert Comment

by:peh803
ID: 12084892
in order to use response.binarywrite, I believe you first need to use the request.binaryread method to retrieve your binary data.

also, do you have the adovbs.inc included?  If not, you'll need to assing a value to your adTypeBinary constant, as they are not inherently available to vbscript applications (forgive me if you already know this)...

peh803
0
 
LVL 19

Accepted Solution

by:
peh803 earned 250 total points
ID: 12084945
adTypeBinary = 1, by the way...

Also, try a Response.Clear right before the call to BinaryWrite.

peh803
0
 

Author Comment

by:hkdcde
ID: 12085066
Response.Clear did it!!!
why did this get it to work?

thanks peh803
0
 
LVL 19

Expert Comment

by:peh803
ID: 12085130
magic.... :)

okay, you don't believe in magic?

the response.binarywrite method is a bit fragile and thus requires gentle treatment... :)

Allowing the script to generate additional textual output (through Response.Write or directly) may corrupt the data sent. For example -- trailing bytes appended to an image streamed binary. It is typically a good idea to use response.end at the end of the script and response.clear at the beginning in order to avoid any output.

anyways, glad to help.

peh803
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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