Hi everyone
How can I embeded an image to OLE Object field using Long Binary data.
and what Long Binary data means and how to use it.

does anyone have any ideas on

I would to display images in my asp page. I am trying to insert the images in to MS Access using long binary data.
so How can I insert a long binary data to ole object field.

thanks in advance

Dani AI

Generated

raised the classic question about storing images in an Access OLE Object field and what "Long Binary" means; echoed the problem and pointed to another thread. In short: "Long Binary" means a BLOB of raw bytes (ADO type adLongVarBinary). An Access OLE Object cell often contains an extra OLE wrapper if the image was embedded from the Access UI, and that wrapper prevents the raw JPEG/PNG bytes from being streamed straight to a browser. For web apps, either store the file on disk and save its path in the DB, or save raw bytes programmatically from ASP (do not use the Access UI to embed images).

Recommended, reliable workflow:

  • Upload the file from the browser (multipart/form-data) and save it to disk or into an ADODB.Stream.
  • Insert raw bytes into the OLE Object/Long Binary column using ADODB.Stream + Recordset.AppendChunk or an ADODB.Command parameter of type adLongVarBinary (205).
  • To serve the image, SELECT the binary and use Response.ContentType + Response.BinaryWrite.
  • If existing records were inserted via the Access UI and appear corrupt on the web, they likely contain an OLE wrapper; re-insert programmatically or use a wrapper-stripping routine (fragile).

Example (classic ASP) — insert and retrieve:

' insert_image.asp
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db.mdb") & ";"

Set stm = Server.CreateObject("ADODB.Stream")
stm.Type = 1 ' adTypeBinary
stm.Open
stm.LoadFromFile Server.MapPath("/uploads/photo.jpg")
blob = stm.Read

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Images", conn, 1, 3
rs.AddNew
rs("FileName") = "photo.jpg"
rs("ImageData").AppendChunk blob
rs.Update

rs.Close
stm.Close
conn.Close
' show_image.asp?id=1
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db.mdb") & ";"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT MimeType, ImageData FROM Images WHERE ID=" & CInt(Request.QueryString("id")), conn, 3, 1

If Not rs.EOF Then
  Response.ContentType = rs("MimeType")
  Response.BinaryWrite rs("ImageData")
End If

rs.Close
conn.Close

For stream/read details see the ADODB Stream object documentation: . Note: Access has size and concurrency limitations; for production sites consider storing files on disk or using a server DB (SQL Server) instead of Jet/ACE.

Recommended Answers

All 2 Replies

Hi everyone
How can I embeded an image to OLE Object field using Long Binary data.
and what Long Binary data means and how to use it.

does anyone have any ideas on

I would to display images in my asp page. I am trying to insert the images in to MS Access using long binary data.
so How can I insert a long binary data to ole object field.

thanks in advance

I have the SAME exact problem here :eek:

If anyone can help us

Thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.