使用 Coldfusion 将图像从 CFHTTP 文件内容转换为二进制数据 [英] Convert an image from CFHTTP filecontent to binary data with Coldfusion

查看:15
本文介绍了使用 Coldfusion 将图像从 CFHTTP 文件内容转换为二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将通过 cfhttp 加载的图像 (jpg) 转换为二进制数据.我不能使用 cffile action="readBinary" 因为它不是本地文件.

I'm trying to convert an image (jpg) loaded via cfhttp to binary data. I can't use cffile action="readBinary" as it is not a local file.

推荐答案

以下是我处理这个问题的方法,我用它每天使用 ColdFusion 8 抓取和处理数百张图像.

Here's how I handle this, and I use this to grab and process hundreds of images a day with ColdFusion 8.

<cfhttp
    timeout="45"
    throwonerror="false"
    url="http://domain/image.jpg"
    method="get"
    useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"
    getasbinary="yes"
    result="local.objGet"
>

<cfset local.objImage = ImageNew(local.objGet.FileContent)>

一旦你有了图像对象,你就可以用它做任何你想做的事情.将它保存到磁盘,调整大小,你命名它:).我显然忽略了所有的错误检查(200 个状态代码,是否是图像等),但这应该可以帮助您入门.

Once you have the image object you can then do whatever you want with it. Save it to disk, resize, you name it :). I've obviously left out all of my error checking (200 status codes, is it an image, etc), but this should get you started.

这篇关于使用 Coldfusion 将图像从 CFHTTP 文件内容转换为二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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