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

时间:2015-12-16 16:03:02

标签: coldfusion cfdocument cfimage

好奇的是这个。

我正在开发一个生成PDF文件的过程,它结合了各种来源的数据。我需要完成的这个过程的最后一部分是合并图像文件。

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

因为文件名如下:B71637CB-A49C-0653-EF813918736BDEB7

这不起作用:

        ---> view containing your three buttons(Current section header view)
        ---> table view
        ---> toolbar

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

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

<img src="#FilePath#">.

3 个答案:

答案 0 :(得分:3)

所以最终的工作结束了:

<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>
亚历克斯的回答让我走上了正确的道路,所以我非常乐意将荣誉留在原地,因为我不能靠近这个地方!

答案 1 :(得分:1)

如果您需要将图像嵌入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>

答案 2 :(得分:0)

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

<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

相关问题