Hi all I am trying to read an image stored in the...
# cfml-general
m
Hi all I am trying to read an image stored in the database in binary Base64. I am able to retrieve it using the following line of code:
<cfcontent type="image/png,image/jpeg, image/gif" variable="#documentimage#">
However, i want it to display as a thumbnail on the page as at present it just just takes over the entire page. Is there anyway to do this. Help would be much appreciated
a
If its base64 encoded then you should be able to do it inline like so
<img src="data:image/png;base64, #documentimage#">
m
thanks @aliaspooryorik when I use that, I get this displayed:
a
OK, so I guess you need to convert from binary.
m
is that using someting like ReadFromBinary
a
this may do it
<img src="data:image/png;base64, #toBase64(documentimage)#">
m
perfect! thanks ever so much 🙏🏻 @aliaspooryorik that did it One more thing if you wouldnt mind.. As well as converting to Base64, I need to encrypt the image to. I have tried encrypt, decrypt but missing something as getting errors
a
What do you mean by encrypting an image? You want to encrypt the base 64 string you store in the database?
m
Yep thats what they have asked for so as well as storing it as binary they also want the image to be encrypted and of course decrypted when outputting the image using the tag you just kindly provided me with
Yes correct 🙂
<!---=== ENCRYPT & STORE THE DOCUMENT===--->
<cfquery name="insertimage">
UPDATE dbo.boi_beneficiaries_individualinfo
SET documentImage = <cfqueryparam CFSQLType="CF_SQL_BLOB" value="#ToBase64(FileReadBinary(Form.FileContents))#">
WHERE boibeneficialownerID = <cfqueryparam value="#arguments.boibeneficialownerID#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>
a
OK so you'd have to encypt the base 64 string before it is saved as binary
m
Thats the code to do the binary bit
So would it eb jsut <cfset documentinage = #encrypt(theimage)#> and then the vase 64 line
a
Have you tried
encryptBinary
?
m
Ah no will give it a try 🙏