简体   繁体   English

来自cfdocument中二进制文件的cfimage

[英]cfimage from binary in cfdocument

I am writing a PDF dynamically, and am creating a QR code on the document for eTicketing purposes 我正在动态编写PDF,并且正在为电子票务目的在文档上创建QR码

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 localurl = yes设置为包括其他图像,这很好用,但是由于我使用API​​调用获取qrCode的二进制文件,因此使用cfimage显示图像,它只显示红色的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 源变量rc.qrCode是一个二进制响应,在我将其放置到cfdocument中之前,它可以正常工作,它生成的URL像这样http://mysite/CFFileServlet/_cf_image/_cfimg-7945382145198648283.PNG作为图像源

i am sure this has todo with localurl and file:///, i just an not knowledgable enough to know why 我敢肯定这与localurl和file:///有关,我只是一个不太了解的原因

Do not need to use physical path rather use relative path to your page. 不需要使用物理路径,而是使用页面的相对路径。 eg If you code in index.cfm of root folder and image inside images folder 例如,如果您在根文件夹的index.cfm中以及在图像文件夹中的图像中进行编码

try <img src="images/header.png"> , Note that it should not start with root path rather relative to your file. 请尝试<img src =“ images / header.png”>,请注意,它不应以根路径开头,而应相对于您的文件。

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. writetoBrowser内部将文件写入硬盘驱动器到其临时位置(局部为C:\\ ColdFusion10 \\ cfusion \\ tmpCache \\ CFFileServlet),并在将其呈现到浏览器时使用“ /CFFileServlet/_cf_image/_cfimg1592404668342998556.PNG”之类的相对路径。 ColdFusion在内部将CFFileServlet目录与所有Coldfusion站点进行内部映射,但注意前导斜杠,这会导致localurl = true出现问题。 Since localurl=true either need physical path or relative path to your document. 由于localurl = true,因此需要物理路径或文档的相对路径。

Good idea is instead of writetobrowser you can write same image to harddrive at your location and give physical path in img tag. 好主意是,您可以将同一张图片写入您所在位置的硬盘驱动器中,并在img标签中提供物理路径,而不是writetobrowser。 I do not this there will any performance issue since ColdFusion internally doing same thing when you are using writetobrowser attribute :) 我不认为这会有任何性能问题,因为当您使用writetobrowser属性时,ColdFusion在内部做同样的事情:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM