Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Response.BinaryWrite not working.

Posted on 2004-09-17
5
Medium Priority
?
437 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 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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 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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

824 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