Insert a image dabase

Results 1 to 2 of 2

Thread: Insert a image dabase

  1. #1
    Join Date
    Dec 1969

    Default Insert a image dabase

    How to save a image file into a binary field of a table.<BR>Thanks for help!

  2. #2
    Join Date
    Dec 1969

    Default RE: Insert a image dabase

    From an article...<BR>Storing Uploaded Data to Database<BR><BR>The data could also be stored in a database. The content-type should also be stored in the database to be able to display the data afterwards. You first have to establish a connection to your database, assuming you already have set up the appropriate DSN:<BR><BR>Set conn = Server.CreateObject("ADODB.Connection")<BR>conn.op en "DSN=wroxdns","user","pass"<BR><BR><BR>Then create a Recordset from that connection:<BR><BR>sql = "SELECT PHOTO, CONTENTTYPE FROM MYTABLE"<BR>Set rs = Server.CreateObject("ADODB.Recordset")<BR>rs.Open sql, conn, 3, 3<BR><BR><BR>When the Recordset is created, you have to put the binary data in the blob field of the database:<BR><BR>picturechunk = picture & chrB(0)<BR>rs.Fields("PICTURE").appendChunk picturechunk<BR>rs.Fields("CONTENTTYPE") = contentType<BR>rs.Update<BR>conn.close<BR><BR><BR> I had to get round a small bug in appendChunk method. In fact, I noticed that when my binary data had an odd number of bytes, the appendChunk method did not transfer the last byte! A solution was to add a chr(0) to be sure to transfer all the bytes. Maybe there is another solution for that, if so, let me know.<BR><BR>To get the image from the database, use the same Recordset and send it back as response to the client with the right content type.<BR><BR><BR>Response.contentType = rs.Fields("CONTENTTYPE")<BR>size = rs.Fields("PICTURE").ActualSize<BR>blob = rs.Fields("PICTURE").GetChunk(size)<BR> narywrite blob<BR><BR><BR>hope this help...<BR><BR>Smo<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts