cfimage from binary in cfdocument

泪湿孤枕 提交于 2019-12-11 08:56:08

问题


I am writing a PDF dynamically, and am creating a QR code on the document for eTicketing purposes

i set my cfdocument localurl=yes to include a different image, which works fine, but since I am using an API call to get the binary for the qrCode, the using cfimage to display the image, it is only showing a red X

<cfdocument format="PDF"  overwrite="Yes" localUrl="yes" pageType = "letter">
<body>
<cfoutput>
<section id="header">

<img src="file:///#ExpandPath('images/header.png')#"/>
<cfimage action="writeToBrowser" source="#rc.qrCode#" />
</cfoutput>
</body>
</html>
</cfdocument>

the source variable rc.qrCode is a binary response that works perfectly until i place inside cfdocument, it generates a url like this http://mysite/CFFileServlet/_cf_image/_cfimg-7945382145198648283.PNG as image source

i am sure this has todo with localurl and file:///, i just an not knowledgable enough to know why


回答1:


Do not need to use physical path rather use relative path to your page. e.g. If you code in index.cfm of root folder and image inside images folder

try <img src="images/header.png"> , Note that it should not start with root path rather relative to your file.

UPDATE

writetoBrowser internally write file to hard drive to it's temporary location (topically, C:\ColdFusion10\cfusion\tmpCache\CFFileServlet) and while rendering it to browser it use relative path like "/CFFileServlet/_cf_image/_cfimg1592404668342998556.PNG", you can say that ColdFusion internally map CFFileServlet directory with all coldfusion site but notice leading forward slash and this makes issue with localurl=true. Since localurl=true either need physical path or relative path to your document.

Good idea is instead of writetobrowser you can write same image to harddrive at your location and give physical path in img tag. I do not this there will any performance issue since ColdFusion internally doing same thing when you are using writetobrowser attribute :)



来源:https://stackoverflow.com/questions/17372320/cfimage-from-binary-in-cfdocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!