使用cfimage显示没有扩展名的文件 [英] Using cfimage to display a file that doesn't have an extension

查看:87
本文介绍了使用cfimage显示没有扩展名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个很好奇。

我正在研究一种生成PDF文件的过程,将各种来源的数据结合在一起。我需要完成的该过程的最后一部分是合并图像文件。

I'm working on a process that generates PDF files, combining data from various sources. The last piece of this process I need to complete is merging in image files.

这实际上非常简单,但是我遇到的问题是图像文件未存储在其中文件扩展名。在本地,我可以更改文件名,但是在生产中这不是一个选择。

This is actually fairly straightforward but the problem I have is the image files aren't stored with file extensions. Locally, I can change the filename, but in production this isn't an option.

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

So because a filename looks like : B71637CB-A49C-0653-EF813918736BDEB7

这将不起作用:

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

<img src="#FilePath#">.

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

So, any ideas on how I can work around this? Here's the code in context:

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


推荐答案

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

If you need to embed the images into the PDF document, try HTML's inline image capabilities:

<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>

这篇关于使用cfimage显示没有扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆