Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome browser does not show images generated by HTTP handler

Basically I have a web site that renders HTML preview of some documents (mainly office). The resulting HTML fragment is included in the page returned by the same web site, however images are returned by HTTP handler from another site with the following links:

<img width="50" height="50" src="http://portal/Service/GetFile.asxh?id=123&inline=true">

For some reason all browsers except Chrome (e.g. IE6/7/8, Firefox, Opera, Safari) show everything just fine, however for these images Chrome shows "broken image" icon. If I choose "Open image in new tab" then the image is shown just fine.

Edit I thought I have solved this issue, but apparently with Fiddler turned on it works fine.

I had context.Response="utf-8" left in code, but removing it had no difference.

Headers:

HTTP/1.1 200 OK
Date: Wed, 05 Jan 2011 14:26:57 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Transfer-Encoding: chunked
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: image/jpeg

Code:

                    context.Response.ContentType = file.ContentType;

                    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    byte[] buff = new byte[BuffSize];
                    using (var stream = repository.GetFileContentsAsStream(file.ContentId))
                    {
                        int bytesRead;
                        do
                        {
                            bytesRead = stream.Read(buff, 0, BuffSize);
                            if (bytesRead > 0)
                            {
                                context.Response.OutputStream.Write(buff, 0, bytesRead);
                            }
                        } while (bytesRead > 0);
                    }

                    context.Response.Flush();
                    context.Response.Close();
like image 359
Arunas Avatar asked Jan 05 '11 13:01

Arunas


People also ask

Why images are not displaying in Chrome?

Open Chrome's menu and head to Settings. From the left pane, click Privacy and security. Click Site Settings > Images. Below Default behavior, select the Sites can show images option.

Why are Web pages not loading images?

Possible causes. The web page is not pointing to the correct URL (location) of the image. The server or computer hosting the image has moved or removed the image, and the web page has not yet been updated. The web page or computer hosting the image is getting too many requests and can't send you the image.

Why can't I see pictures on websites Google Chrome Android?

Check if the “show images” setting is enabled Click the three vertical dots at the top right corner and open Settings. Go to the Privacy and security tab in the left-hand menu and click Site settings. Go to the Content section and click Images. Ensure that the Site can show images option is selected.


2 Answers

I'm pretty sure Chrome requires the Length to be set for images, so try adding the Content-Length header to your response when handling the image.

like image 109
Pauli Østerø Avatar answered Oct 27 '22 12:10

Pauli Østerø


It's the context.Response.Close(); Chrome doesn't like it. Get rid of that line and all will be good. I fought with this for months.

like image 45
David L. Sargent Avatar answered Oct 27 '22 14:10

David L. Sargent