0

I am connecting to my MS SQL server (2008) where I have stored JPG's as BLOB files and am retrieving them in a single page (displayImage.aspx) which I then show on other pages to display the image. This works great in all browsers on a Windows machine. However, from the OS X machines there is extended data being shown in the browser and the pictures are not displaying. (screenshot:http://i.imgur.com/133I8.png) Any suggestions? Code is below:

string image = Request.QueryString["image"];

if (image == null){
    image = "no_image.jpg";
}


    SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["CONNECTIONSTRING"].ToString());

    objConn.Open();

    string sTSQL =

                        "SELECT [data] " +
                        "FROM [DBTABLE] " +
                        "WHERE filename = '" + image + "'";

    SqlCommand objCmd = new SqlCommand(sTSQL, objConn);
    objCmd.CommandType = CommandType.Text;

    SqlDataReader dr = objCmd.ExecuteReader();
    dr.Read();

    Response.BinaryWrite((byte[])dr["data"]);

    objConn.Close();
Geekender
  • 799
  • 4
  • 9
  • 18
  • Are you perhaps not setting Resonse.ContentType to "image/jpeg" (or "image/png", etc. depending on the image type)? – Jon Hanna Jan 25 '12 at 00:07

2 Answers2

3

It appears you are not providing a MIME type with your response. If you do, the browser won't have to guess.

Tetsujin no Oni
  • 7,300
  • 2
  • 29
  • 46
1

Have you tried adding this line beneath the Response.BinaryWrite() line? (see below)

Response.End();

Sounds like it worked for this other, possibly-related question: Reading a binary file and using Response.BinaryWrite() ...

Community
  • 1
  • 1
summea
  • 7,390
  • 4
  • 32
  • 48