Embedded image
A client recently decided to start storing all of their images in a database and usually we would point the image source to a cfm page, where we'd do something like this:
-
request.uploadedPic = application.staffManager.getStaffImage(session.user.getId());
-
context = getPageContext();
-
context.setFlushOutput(false);
-
response = context.getResponse().getResponse();
-
out = response.getOutputStream();
-
response.setContentType("image/jpeg");
-
response.setContentLength(arrayLen(request.uploadedPic['staffPhoto'][1]));
-
out.write(request.uploadedPic['staffPhoto'][1]);
-
out.flush();
-
response.reset();
-
out.close();
Which worked nicely until I read about some performance issues with http calls and the cfdocument tag. Zac (yes his name pops up a lot in this blog), put me onto directly embedding the image into the source, like such:
-
<img src="data:image/jpeg;base64,<cfoutput>#BinaryEncode(request.uploadedPic['staffPhoto'][1],'Base64')#</cfoutput>" alt="Embedded Image" />
No need to make a http call to display the image anymore.
About this entry
You’re currently reading “Embedded image,” an entry on gregs
- Published:
- Tuesday, March 13th, 2007 at 3:26 pm
- Author:
- gregs
- Category:
- ColdFusion
4 Comments
Jump to comment form | comments rss | trackback uri