Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Problem with asp page returning a jpg image...

Reply
Thread Tools

Problem with asp page returning a jpg image...

 
 
Peter
Guest
Posts: n/a
 
      10-04-2006
I have a problem with a page show_image.asp that returns a jpg image under
Windows XP Pro SP2. The page sets content type as:

Response.ContentType = "image/jpg"

While this works perfectly fine on most machines, on some machines I
experience this problem:

When loading the page a window pops up that asks if I want to open the
document show_page.asp. When I click "Open" Interdev pops up and opens up a
window titled show_image.asp but the contents of that page has a few html
tags at the top followed by the binary jpg data. In fact, if I delete the
html tags and save the page as something.jpg and then look at it, it shows
the expected image.

I've noticed this problem before and found on some machines that disabling
server side debugging for the virtual directory in IIS admin does the trick.
On other occasions, I recreated the server extensions and that solved it. I
have never completely managed to understand why this happens and a reliable
way to fix it.

Any ideas?


 
Reply With Quote
 
 
 
 
Larry Bud
Guest
Posts: n/a
 
      10-10-2006

Peter wrote:
> I have a problem with a page show_image.asp that returns a jpg image under
> Windows XP Pro SP2. The page sets content type as:
>
> Response.ContentType = "image/jpg"
>
> While this works perfectly fine on most machines, on some machines I
> experience this problem:
>
> When loading the page a window pops up that asks if I want to open the
> document show_page.asp. When I click "Open" Interdev pops up and opens up a
> window titled show_image.asp but the contents of that page has a few html
> tags at the top followed by the binary jpg data.


Why not show us "show_page.asp"??

 
Reply With Quote
 
 
 
 
Peter
Guest
Posts: n/a
 
      10-12-2006
OK, here it goes:

test.asp
--------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>Test Warehouse layout</title>
</head>
<body>
<img src="show_image.asp">
</body>
</html>


show_image.asp:
---------------
<%@ Language=VBScript %>
<%
Option Explicit

Response.Expires = -1
Response.Buffer = True
Response.ContentType = "image/jpg"

Dim objWarehouse

Set objWarehouse = mlobjAPP3Database.Warehouse()

If Not objWarehouse Is Nothing Then
Response.BinaryWrite objWarehouse.LayoutJPG()
End If
%>

Please don't forget that this works on most machines. However, I frequently
have troubles on development machines and wonder if it has something to do
with server/client side debugging being enabled for IIS or if it has
something to do with frontpage or interdev IIS extensions.

Pete

"Larry Bud" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Peter wrote:
>> I have a problem with a page show_image.asp that returns a jpg image
>> under
>> Windows XP Pro SP2. The page sets content type as:
>>
>> Response.ContentType = "image/jpg"
>>
>> While this works perfectly fine on most machines, on some machines I
>> experience this problem:
>>
>> When loading the page a window pops up that asks if I want to open the
>> document show_image.asp. When I click "Open" Interdev pops up and opens
>> up a
>> window titled show_image.asp but the contents of that page has a few html
>> tags at the top followed by the binary jpg data.

>
> Why not show us "show_image.asp"??
>



 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      10-12-2006
Peter wrote:
> Response.ContentType = "image/jpg"


If you look at the content-type sent by the browser when you UPLOAD a jpg
file, you will find that it is "image/jpeg", not "image/jpg". Furthermore,
IIS 6 sends "image/jpeg" in the content-type header for .jpg requests. Try
changing your code to a recognized content type.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      10-12-2006
Thanks heaps Dave, your reply was spot on and fix my problem!!!

"Dave Anderson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Peter wrote:
>> Response.ContentType = "image/jpg"

>
> If you look at the content-type sent by the browser when you UPLOAD a jpg
> file, you will find that it is "image/jpeg", not "image/jpg". Furthermore,
> IIS 6 sends "image/jpeg" in the content-type header for .jpg requests. Try
> changing your code to a recognized content type.
>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per message.
> Use of this email address implies consent to these terms.
>



 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      11-16-2006
Now I have a similar problem again on another machine.

In the message below I used Response.ContentType = "image/jpg" and after
changing it to Response.ContentType = "image/jpeg" it alworked on the
machine I had trouble back then.

Now I have a similar problem once again even though I am now returning the
correct mime type.

The behaviour is as follows:

IE 7.0:
http://localhost/test.asp simply shows the icon for a missing image instead
of the image
http://localhost/show_image.asp shows some raw image data

Mozilla Firefox 2.0:
http://localhost/test.asp simply shows the icon for a missing image instead
of the image
http://localhost/show_image.asp shows the URL as text in the client area
instead of the image

I ammendet show_image.asp to also write the binary data to an physical file
c:\temp\image.jpg. I can see that the image is updated each time i request
either of the two URL's and this works fine. Furthermore, the image looks
fine too.

I really have no idea what is wrong with... Is this an incorrect approach???

Pete


"Peter" <peteATkapiti.co.nz> wrote in message
news:(E-Mail Removed)...
> OK, here it goes:
>
> test.asp
> --------
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html">
> <title>Test Warehouse layout</title>
> </head>
> <body>
> <img src="show_image.asp">
> </body>
> </html>
>
>
> show_image.asp:
> ---------------
> <%@ Language=VBScript %>
> <%
> Option Explicit
>
> Response.Expires = -1
> Response.Buffer = True
> Response.ContentType = "image/jpg"
>
> Dim objWarehouse
>
> Set objWarehouse = mlobjAPP3Database.Warehouse()
>
> If Not objWarehouse Is Nothing Then
> Response.BinaryWrite objWarehouse.LayoutJPG()
> End If
> %>
>
> Please don't forget that this works on most machines. However, I
> frequently have troubles on development machines and wonder if it has
> something to do with server/client side debugging being enabled for IIS or
> if it has something to do with frontpage or interdev IIS extensions.
>
> Pete
>
> "Larry Bud" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>>
>> Peter wrote:
>>> I have a problem with a page show_image.asp that returns a jpg image
>>> under
>>> Windows XP Pro SP2. The page sets content type as:
>>>
>>> Response.ContentType = "image/jpg"
>>>
>>> While this works perfectly fine on most machines, on some machines I
>>> experience this problem:
>>>
>>> When loading the page a window pops up that asks if I want to open the
>>> document show_image.asp. When I click "Open" Interdev pops up and opens
>>> up a
>>> window titled show_image.asp but the contents of that page has a few
>>> html
>>> tags at the top followed by the binary jpg data.

>>
>> Why not show us "show_image.asp"??
>>

>
>



 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      11-17-2006
Peter wrote:
> Now I have a similar problem again on another machine.
>
> In the message below I used Response.ContentType = "image/jpg" and
> after changing it to Response.ContentType = "image/jpeg" it alworked
> on the machine I had trouble back then.
>
> Now I have a similar problem once again even though I am now
> returning the correct mime type.
>
> The behaviour is as follows:
>
> IE 7.0:
> http://localhost/test.asp simply shows the icon for a missing image
> instead of the image
> http://localhost/show_image.asp shows some raw image data
>
> Mozilla Firefox 2.0:
> http://localhost/test.asp simply shows the icon for a missing image
> instead of the image
> http://localhost/show_image.asp shows the URL as text in the client
> area instead of the image


I see several conditions here that are not accounted for:

>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
>>> If Not objWarehouse Is Nothing Then
>>> Response.BinaryWrite objWarehouse.LayoutJPG()
>>> End If


Since we know almost nothing about mlobjAPP3Database, it isn't clear that
the choices are [Nothing] and [an object with nontrivial method
LayoutJPG()]. Moreover, the method name suggests the image is always in the
jpeg format. Are you certain this is the case?


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      11-19-2006
"Dave Anderson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Peter wrote:
>> Now I have a similar problem again on another machine.
>>
>> In the message below I used Response.ContentType = "image/jpg" and
>> after changing it to Response.ContentType = "image/jpeg" it alworked
>> on the machine I had trouble back then.
>>
>> Now I have a similar problem once again even though I am now
>> returning the correct mime type.
>>
>> The behaviour is as follows:
>>
>> IE 7.0:
>> http://localhost/test.asp simply shows the icon for a missing image
>> instead of the image
>> http://localhost/show_image.asp shows some raw image data
>>
>> Mozilla Firefox 2.0:
>> http://localhost/test.asp simply shows the icon for a missing image
>> instead of the image
>> http://localhost/show_image.asp shows the URL as text in the client
>> area instead of the image

>
> I see several conditions here that are not accounted for:
>
>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
>>>> If Not objWarehouse Is Nothing Then
>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
>>>> End If

>
> Since we know almost nothing about mlobjAPP3Database, it isn't clear that
> the choices are [Nothing] and [an object with nontrivial method
> LayoutJPG()]. Moreover, the method name suggests the image is always in
> the jpeg format. Are you certain this is the case?


I accept your concerns, but I have reduced to code to the protions which are
relevant for this dicussion. The problem is not with my code, the problem is
somewhere with the configuration of IIS.

I have expanded show_image.asp with the following function:

Function SaveBinaryData(FileName, ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary

'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write ByteArray

'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function

Now not only do I write the raw data back to the client, I also write it to
a physical file:

Response.BinaryWrite objWarehouse.LayoutJPG()
SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()

Not only can I see that c:\temp\mypic.jpg get's written correctly everytime
I request the page from the web server, my web browsers and image viewers
show the expected image when I open the file explicitly.

There must be something wrong with IIS, I suspect it has something to do
with front page server extensions or extensions needed for MS InterDev.

Pete


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      11-19-2006

"Peter" <peteATkapiti.co.nz> wrote in message
news:(E-Mail Removed)...
> "Dave Anderson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Peter wrote:
>>> Now I have a similar problem again on another machine.
>>>
>>> In the message below I used Response.ContentType = "image/jpg" and
>>> after changing it to Response.ContentType = "image/jpeg" it alworked
>>> on the machine I had trouble back then.
>>>
>>> Now I have a similar problem once again even though I am now
>>> returning the correct mime type.
>>>
>>> The behaviour is as follows:
>>>
>>> IE 7.0:
>>> http://localhost/test.asp simply shows the icon for a missing image
>>> instead of the image
>>> http://localhost/show_image.asp shows some raw image data
>>>
>>> Mozilla Firefox 2.0:
>>> http://localhost/test.asp simply shows the icon for a missing image
>>> instead of the image
>>> http://localhost/show_image.asp shows the URL as text in the client
>>> area instead of the image

>>
>> I see several conditions here that are not accounted for:
>>
>>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
>>>>> If Not objWarehouse Is Nothing Then
>>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
>>>>> End If

>>
>> Since we know almost nothing about mlobjAPP3Database, it isn't clear that
>> the choices are [Nothing] and [an object with nontrivial method
>> LayoutJPG()]. Moreover, the method name suggests the image is always in
>> the jpeg format. Are you certain this is the case?

>
> I accept your concerns, but I have reduced to code to the protions which
> are relevant for this dicussion. The problem is not with my code, the
> problem is somewhere with the configuration of IIS.
>
> I have expanded show_image.asp with the following function:
>
> Function SaveBinaryData(FileName, ByteArray)
> Const adTypeBinary = 1
> Const adSaveCreateOverWrite = 2
>
> 'Create Stream object
> Dim BinaryStream
> Set BinaryStream = CreateObject("ADODB.Stream")
>
> 'Specify stream type - we want To save binary data.
> BinaryStream.Type = adTypeBinary
>
> 'Open the stream And write binary data To the object
> BinaryStream.Open
> BinaryStream.Write ByteArray
>
> 'Save binary data To disk
> BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
> End Function
>
> Now not only do I write the raw data back to the client, I also write it
> to a physical file:
>
> Response.BinaryWrite objWarehouse.LayoutJPG()
> SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()
>
> Not only can I see that c:\temp\mypic.jpg get's written correctly
> everytime I request the page from the web server, my web browsers and
> image viewers show the expected image when I open the file explicitly.
>
> There must be something wrong with IIS, I suspect it has something to do
> with front page server extensions or extensions needed for MS InterDev.


Surprise, surprise...

I now find that if I change show_image.asp as follows all works fine (note
that all I changed was inserting a Response.Clear before and Response.Flush
after writing the binary data to the output stream). Why would that be?

<%@ Language=VBScript %>
<%
Option Explicit

Response.Expires = -1
Response.Buffer = True

Dim objWarehouse

Set objWarehouse = mlobjAPP3Database.Warehouse()

If Not objWarehouse Is Nothing Then
Response.Clear
Response.ContentType = "image/jpeg"
Response.BinaryWrite objWarehouse.LayoutJPG()
Response.Flush
End If
%>


 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      11-20-2006

"Peter" <peteATkapiti.co.nz> wrote in message
news:(E-Mail Removed)...
>
> "Peter" <peteATkapiti.co.nz> wrote in message
> news:(E-Mail Removed)...
> > "Dave Anderson" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Peter wrote:
> >>> Now I have a similar problem again on another machine.
> >>>
> >>> In the message below I used Response.ContentType = "image/jpg" and
> >>> after changing it to Response.ContentType = "image/jpeg" it alworked
> >>> on the machine I had trouble back then.
> >>>
> >>> Now I have a similar problem once again even though I am now
> >>> returning the correct mime type.
> >>>
> >>> The behaviour is as follows:
> >>>
> >>> IE 7.0:
> >>> http://localhost/test.asp simply shows the icon for a missing image
> >>> instead of the image
> >>> http://localhost/show_image.asp shows some raw image data
> >>>
> >>> Mozilla Firefox 2.0:
> >>> http://localhost/test.asp simply shows the icon for a missing image
> >>> instead of the image
> >>> http://localhost/show_image.asp shows the URL as text in the client
> >>> area instead of the image
> >>
> >> I see several conditions here that are not accounted for:
> >>
> >>>>> Set objWarehouse = mlobjAPP3Database.Warehouse()
> >>>>> If Not objWarehouse Is Nothing Then
> >>>>> Response.BinaryWrite objWarehouse.LayoutJPG()
> >>>>> End If
> >>
> >> Since we know almost nothing about mlobjAPP3Database, it isn't clear

that
> >> the choices are [Nothing] and [an object with nontrivial method
> >> LayoutJPG()]. Moreover, the method name suggests the image is always in
> >> the jpeg format. Are you certain this is the case?

> >
> > I accept your concerns, but I have reduced to code to the protions which
> > are relevant for this dicussion. The problem is not with my code, the
> > problem is somewhere with the configuration of IIS.
> >
> > I have expanded show_image.asp with the following function:
> >
> > Function SaveBinaryData(FileName, ByteArray)
> > Const adTypeBinary = 1
> > Const adSaveCreateOverWrite = 2
> >
> > 'Create Stream object
> > Dim BinaryStream
> > Set BinaryStream = CreateObject("ADODB.Stream")
> >
> > 'Specify stream type - we want To save binary data.
> > BinaryStream.Type = adTypeBinary
> >
> > 'Open the stream And write binary data To the object
> > BinaryStream.Open
> > BinaryStream.Write ByteArray
> >
> > 'Save binary data To disk
> > BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
> > End Function
> >
> > Now not only do I write the raw data back to the client, I also write it
> > to a physical file:
> >
> > Response.BinaryWrite objWarehouse.LayoutJPG()
> > SaveBinaryData "c:\temp\mypic.jpg", objWarehouse.LayoutJPG()
> >
> > Not only can I see that c:\temp\mypic.jpg get's written correctly
> > everytime I request the page from the web server, my web browsers and
> > image viewers show the expected image when I open the file explicitly.
> >
> > There must be something wrong with IIS, I suspect it has something to do
> > with front page server extensions or extensions needed for MS InterDev.

>
> Surprise, surprise...
>
> I now find that if I change show_image.asp as follows all works fine (note
> that all I changed was inserting a Response.Clear before and

Response.Flush
> after writing the binary data to the output stream). Why would that be?
>
> <%@ Language=VBScript %>
> <%
> Option Explicit
>
> Response.Expires = -1
> Response.Buffer = True
>
> Dim objWarehouse
>
> Set objWarehouse = mlobjAPP3Database.Warehouse()
>
> If Not objWarehouse Is Nothing Then
> Response.Clear
> Response.ContentType = "image/jpeg"
> Response.BinaryWrite objWarehouse.LayoutJPG()
> Response.Flush
> End If
> %>


Sounds like there is some code running before this that was generating some
output in the buffer.
does the page have an include file that might be doing this?
Is the page arrived at via Server.Transfer or Server.Execute?

If you remove the .Flush does the problem come back?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JPG's were nor recognised as JPG's Matthias HTML 5 06-01-2004 11:50 AM
Wrong image size of JPG after TIFF to JPG conversion with JAI Roland Java 0 05-12-2004 03:52 PM
ASP changes Big JPG -> Small JPG Yannick ASP General 6 02-03-2004 03:06 AM
DSCN1234.JPG vs dscn1234.jpg on COOLPIX 885 Michel Boivin, ing. Digital Photography 0 12-26-2003 06:22 PM
Calling a html page from an asp page then returning to the next statement on the original asp page Chuck ASP General 0 07-05-2003 02:00 AM



Advertisments