使用 cfimage 显示没有扩展名的文件

Using cfimage to display a file that doesn't have an extension

好奇这个。

我正在研究一个生成 PDF 文件的过程,结合来自不同来源的数据。我需要完成的这个过程的最后一部分是合并图像文件。

这实际上相当简单,但我遇到的问题是图像文件没有以文件扩展名存储。在本地,我可以更改文件名,但在生产中这不是一个选项。

因为文件名看起来像:B71637CB-A49C-0653-EF813918736BDEB7

这行不通:

<cfimage action="writeTobrowser" source="#FilePath#> 

<img src="#FilePath#">.

那么,关于如何解决这个问题有什么想法吗?这是上下文中的代码:

<cfdocument format="PDF" name="report" filename="#fileToDownloadimage#" overwrite="yes">
    <cfdocumentsection>
        <cfimage action="writeTobrowser" source="#FilePath#.jpg">
    </cfdocumentsection>
</cfdocument>

您可以尝试创建一个 cfm 页面,使用 cfcontent 输出您的内容,如:

<cfcontent type="image/jpg" file="path/#fielpath#">

然后你会把那个 cfm 页面作为你的图片的来源,如

<img src="myFancyImageOuputer.cfm?image=#filepath#">

这应该可行,但可能需要反复试验。 :)

Ray 在这里有一些额外的提示:

http://www.raymondcamden.com/2007/09/14/Serving-up-CFIMages-via-Image-Tags-and-a-NonCF-Friday-contest

如果您需要将图像嵌入到 PDF 文档中,请尝试 HTML 的内联图像功能:

<cfset fileLocation         = "/path/to/images/B71637CB-A49C-0653-EF813918736BDEB7">
<cfset imageContent         = fileReadBinary(fileLocation)>
<cfset imageContentAsBase64 = toBase64(imageContent)>

<cfoutput>
    <img src="data:image/jpeg;base64, #imageContentAsBase64#" />
</cfoutput>

所以这是最终起作用的:

<cfdocument format="PDF" name="report" filename="#fileToDownloadimage#" overwrite="yes">
    <cfdocumentsection>
        <cfset fileObject = fileReadBinary('#FilePath#') />
        <cfset imageObject = imageNew(fileObject) />
        <cfimage action="writeTobrowser" source="#imageObject#">
    </cfdocumentsection>
</cfdocument>

Alex 的回答让我走上了正确的道路,所以我很高兴将荣誉留在原地,因为我离这还差得很远!