Response.ContentType problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chris3000
    New Member
    • Oct 2006
    • 9

    Response.ContentType problems

    I got this in my code : Response.Conten tType = "image/jpg" or image/jpeg or gif or bmp

    I cant open this asp page with internet explorer.

    I get a message error: Internet explorer cannot download test1.asp from localhost or when i cut &paste the code(from that file) in a new document in frontpage internet explorer want to download the file or open it with frontpage.

    I just wanna know why yesterday I work with the same exact page and I dont get this error message and download things. And what's the matter with Response.Conten tType ?

    And when it work the only thing I got is tons of ascii characters like this : $ÿÿÿÿPac kagePackage.. . why ?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    By default the Response.Conten tType is set to text/html which will allow for the content to be written to and understood by the browser.

    If you change the content type, browsers can no longer understand what has been sent to them since they cannot interpert anything except text/html.

    If you change content type then the content needs be opened with an application that understands that content type.

    I'm not sure if this helps you at all as I'm not quite clear on what you are trying to do.

    Comment

    • Chris3000
      New Member
      • Oct 2006
      • 9

      #3
      Originally posted by Frinavale
      By default the Response.Conten tType is set to text/html which will allow for the content to be written to and understood by the browser.

      If you change the content type, browsers can no longer understand what has been sent to them since they cannot interpert anything except text/html.

      If you change content type then the content needs be opened with an application that understands that content type.

      I'm not sure if this helps you at all as I'm not quite clear on what you are trying to do.
      Hi :)

      Here is the code :

      <%
      set conn=server.Cre ateObject("ADOD B.Connection")
      conn.Provider=" Microsoft.jet.O LEDB.4.0"
      conn.Open "F:/projet/test1.mdb"

      set rs= conn.Execute("S ELECT photo FROM photos where ID=1")

      Response.Conten tType="image/jpg"
      Response.Binary Write(rs("photo "))

      conn.Close
      %>

      Normally i would expect to see a image from the database
      But the only thing I got is tons of ascii characters like this : $ÿÿÿÿPac kagePackage

      Another problem
      And now after some refresh (code hasnt change) Internet Explorer give me a messagebox with prompts as follows:
      =============== =============== ====
      Title: File Download - Security Warning
      Name: Setup.exe
      From: localhost

      Buttons: [Run] [Save] [Cancel]

      While files from internet can be useful, this file type can potentially harm your computer. If you do not trust the source, do not run or save this software. (link: ) What's the risk?
      =============== =============== ==

      i copy paste the code in a new asp file
      it works like 3 or 4 times (doing some refresh) and then the messagebox come back.

      I try other browser like Firefox and Opera and its the same thing
      I tried to change security level for intranet too, but i don't know which parameter to change.

      thanx for your help
      Chris

      Comment

      • r_o
        New Member
        • Jul 2006
        • 35

        #4
        hey man
        i don understand why you wanna set the content type to image/jpeg because by default IE and most browsers can read it easily
        so you just insert the image into the web page and the browser will display it for ya

        Comment

        • Chris3000
          New Member
          • Oct 2006
          • 9

          #5
          Originally posted by r_o
          hey man
          i don understand why you wanna set the content type to image/jpeg because by default IE and most browsers can read it easily
          so you just insert the image into the web page and the browser will display it for ya
          Ok so give me the code that take a image from a database and display it.

          <%
          set conn=server.Cre ateObject("ADOD B.Connection")
          conn.Provider=" Microsoft.jet.O LEDB.4.0"
          conn.Open "F:/projet/test1.mdb"

          set rs= conn.Execute("S ELECT photo FROM photos where ID=1")

          Response.Conten tType="image/jpg"
          Response.Binary Write(rs("photo "))

          conn.Close
          %>

          thanx
          Chris

          Comment

          • r_o
            New Member
            • Jul 2006
            • 35

            #6
            Response.Conten tType="image/jpg"
            Response.Binary Write(rs("photo "))
            i think response.binary write(rs("photo ")) should do it itself

            Comment

            • Chris3000
              New Member
              • Oct 2006
              • 9

              #7
              Originally posted by r_o
              i think response.binary write(rs("photo ")) should do it itself
              The code :

              <%
              set conn=server.Cre ateObject("ADOD B.Connection")
              conn.Provider=" Microsoft.jet.o ledb.4.0"
              conn.Open(serve r.MapPath("test 1.mdb"))
              set rs= conn.Execute("S ELECT photo FROM photos where ID=1")
              %>

              <img src="<%Response .BinaryWrite(rs ("photo"))%> ">

              <% conn.Close %>

              I think you 're right on this but the only thing I get is ascii code like this : ÿÐÿõ«®C¸Yö>w[–¸Œç1sÐåA... .

              Don't know why :( Can you help me on that

              Thanx for the help
              Chris

              Comment

              Working...