Convert image from CFHTTP file to binary data using Coldfusion

I am trying to convert an image (jpg) uploaded via cfhttp to binary data. I can not use cffile action="readBinary" because it is not a local file.

+4
source share
2 answers

This is how I handle it, and I use it to capture and process hundreds of images per day using 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)> 

As soon as you have an image object, you can do whatever you want with it. Save it to disk, change its size, name it :). I obviously did not take into account all my error checks (200 status codes, this image, etc.), but this should help you get started.

+13
source

I did the following, which seems to work:

 <cfhttp url="http://foo.com/someImage.jpg" method="get" timeout="3" result="resp"> </cfhttp> <cfreturn resp.fileContent.toByteArray() /> 
+5
source

All Articles