Solved

Response.BinaryWrite not working.

Posted on 2004-09-17
5
415 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now