boo*_*dle 7 coldfusion coldfusion-9
我在Coldfusion 9服务器上有一项服务,可以为我们动态创建图像横幅.一台单独的机器必须保存这些文件,例如:
wget http://myserver.com/services/local/bannerCreator/250x250-v3.cfm?prodID=3&percentSaving=19
Run Code Online (Sandbox Code Playgroud)
问题是我想不出如何在不使用临时文件的情况下让coldfusion写出二进制数据.在这一刻,图像只显示为这样的图像标签:
<cfimage action = "writeToBrowser" source="#banner#" width="#banner.width#" height="#banner.height#" />
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?或者我应该只使用临时文件?
Ada*_*tle 12
我无法测试,因为您没有提供有关图像生成方式的任何示例代码,但您是否尝试过这一行?
<cfcontent reset="true" variable="#imageData#" type="image/jpg" />
Run Code Online (Sandbox Code Playgroud)
更新:所以我继续创建自己的形象; 我假设你正在做类似的事情.这对我很有用:
<cfset img = imageNew("",200,200,"rgb","red") />
<cfcontent variable="#toBinary(toBase64(img))#" type="image/png" reset="true" />
Run Code Online (Sandbox Code Playgroud)
这无需写入文件,也无需使用虚拟文件系统("ramdisk")
如果你有文件/图像的二进制字节,你可以用它的内容替换输出缓冲区,如下所示:
<cfscript>
// eg. this is how you get a file as a binary stream
// var fileBytes = fileReadBinary( '/path/to/your/file.jpg' );
// get the http response
var response = getPageContext().getFusionContext().getResponse();
// set the appropriate mime type
response.setHeader( 'Content-Type', 'image/jpg' );
// replace the output stream contents with the binary
response.getOutputStream().writeThrough( fileBytes );
// leave immediately to ensure no whitespace is added
abort;
</cfscript>
Run Code Online (Sandbox Code Playgroud)
几乎<cfcontent>与你使用时有什么关系reset="true"
这种方法的优点<cfcontent>是我们可以在基于cfscript的cfcs中编写它.