BinaryWrite


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: BinaryWrite

  1. #1
    Justin Guest

    BinaryWrite


    Do you know how to call a picture from SQL database and write it into an ASP
    page?

    Right now, the following code did not work:

    Response.BinaryWrite rs2("Emp_Photo")

    PLEASE HELP!

  2. #2
    Russell Jones Guest

    Re: BinaryWrite

    It doesn't work because the client sends a *separate request* for the
    picture data when it parses the <img> tag. What you want to do is write a
    non-image URL into the image tag's src attribute, for example:
    <img src="imagePage.asp">

    The client will parse that tag and request the file from the server. In the
    "imagePage.asp" file, you should respond by retrieving the picture data from
    the database, setting the Response.ContentType property to "image/gif" or
    whatever the correct MIME type for your image is, and *then* using
    Response.BinaryWrite to send the data to the client.

    Of course, you can do all this in one page by creating a parameter that you
    append to the request, e.g.
    <img src="thisPage.asp?Image=true"> or something similar. In "thisPage.asp"
    you would check the Request.QueryString("Image") variable and return the
    image as detailed above if the parameter is "true", else return the initial
    HTML for the page if the parameter value is anything else or if the
    parameter is absent. Similarly, you can create a single page that will
    return *any* image, from either a database or from a file, given a parameter
    like "ImageID" or "ImageFile".

    HTH,
    Russell Jones
    Executive Editor,
    DevX.com
    "Justin" <Justin.Marshall@Takata.com> wrote in message
    news:3cbebf36$1@10.1.10.29...
    >
    > Do you know how to call a picture from SQL database and write it into an

    ASP
    > page?
    >
    > Right now, the following code did not work:
    >
    > Response.BinaryWrite rs2("Emp_Photo")
    >
    > PLEASE HELP!




  3. #3
    Devin Knutson Guest

    Re: BinaryWrite

    "Justin" <Justin.Marshall@Takata.com> wrote in message
    news:3cbebf36$1@10.1.10.29...
    >
    > Do you know how to call a picture from SQL database and write it

    into an ASP
    > page?
    >
    > Right now, the following code did not work:
    >
    > Response.BinaryWrite rs2("Emp_Photo")
    >
    > PLEASE HELP!


    Also note that you cannot use Response.BinaryWrite in the same
    request with a standard Response.Write. The two are mutually
    exclusive. In other words, once you have written anything to the
    header of a response, you cannot write any binary information, and
    vice-versa.

    What I've done is to create an ASP page specifically for BLOB field
    images. It includes arguments for the table name, field name and
    key information so that I can just move it around on any site when I
    need it, and use it over and over again. It's called like this:

    <img
    src="getImage.asp?Table=pics&Field=image1&Keyname=imgID&Keyvalue=102
    8">

    getImage.asp then does

    SELECT image1 FROM pics WHERE imgID = 1028

    and uses Response.BinaryWrite to spit the image back to the client.

    HTH!

    --
    Devin Knutson
    ==================================
    What God wants, God gets.
    God help us all...



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center