OVH Cloud OVH Cloud

Dans une page ASP une image stockée dans un base Access ?

1 réponse
Avatar
Fabien
Bonjour,
aprés deux jours de recherche sur le Web je viens ici poser ma question.
Comment faire pour afficher une image stockée dans un base Access ?
Le site de microsoft donne une solution qui passe par la création d'un COM
en VB mais je n'ai pas VB :-(.
La commande Response.binaryWrite Rst("Logo") ne donne rien parceque la base
est Access :-(
Merci

1 réponse

Avatar
Sylvain Lafontaine
Les images et autres documents binaires (Word, PDF, etc.) de type OLE Object
dans Access sont stockées avec un header de 78 bytes. Il suffit de tronquer
ce header et de dumper le reste:

' Image file processing variables
Dim block_count
Dim image_chunk
Dim image_file_extension
Dim image_file_size
Dim offset, remainder

Dim ADO_field_header, block_size
ADO_field_header = 78
block_size = 256
on error resume next

' Compute the image file's size (in bytes) by subtracting
' the bytes within the ADO field header.

' Then, after discarding the header bytes stored at the
' start of the image field's column within the ADO
' Recordset object, Compute the number of "block size"
' blocks there are within the image field.

image_chunk = rs.fields("Logo").GetChunk(ADO_field_header)
image_file_size = rs.fields("Logo").ActualSize - ADO_field_header
block_count = image_file_size block_size

' To make the last write ouptput a full "block size"
' buffer, divide the block size into the image's total
' size and then retrieve and write to the disk file any
' "left over" bytes so that when looping the read you
' always have exactly some number of "block size" (and no
' extra) bytes to read and write

remainder = image_file_size Mod block_size

If Remainder > 0 Then
Response.BinaryWrite rs.fields("Logo").GetChunk(remainder)
End If

' Work through the image field "block size" bytes at a time
' and append each block of bytes onto the disk file.

offset = remainder

Do While Offset < image_file_size
Response.BinaryWrite rs.fields("Logo").GetChunk(block_size)
offset = offset + block_size
Loop


N'oubliez pas de mettre les bonnes valeurs pour Response.ContentType et de
Response.ContentLength de préférence.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC


"Fabien" <..> wrote in message
news:42de4813$0$22306$
Bonjour,
aprés deux jours de recherche sur le Web je viens ici poser ma question.
Comment faire pour afficher une image stockée dans un base Access ?
Le site de microsoft donne une solution qui passe par la création d'un COM
en VB mais je n'ai pas VB :-(.
La commande Response.binaryWrite Rst("Logo") ne donne rien parceque la
base est Access :-(
Merci