Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Response.BinaryWrite not working.

Posted on 2004-09-17
5
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 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