CFHTTP POST, result is image, how to save

Viewed 474

I found a web-site that clears exif data from an image. The source can either be an uploaded picture or a URL. I thought, perhaps, I could use this with CFHTTP to do this automatically for pictures I post to my web-site. I know I can probably run my images manually through this site before I upload them to my site. Call this an exercise if you want.

Here is the code I am using, which basically matches the form source on this very simple web-site (link)

<cfhttp method="POST" url="https://www.verexif.com/en/quitar.php" result="result"  >
    <cfhttpparam name="foto_url" type="formfield" value="{myimageurl}">
</cfhttp>

When I CFDUMP the result, I get the following: CFDUMP of CFHTTP Result

When I try to use DeserializeJSON(result.Filecontent), it gives me a ColdFusion error:

ColdFusion error

When I url-encode my original URL in the CFHTTP tag, the result.filecontent contains the source code of the original web-site.

As can be seen in the first image above, there is a file called 'foto_no_exif.jpg' included in the output. This is the file I need to download. How can I do this ?

1 Answers

In your current dump, you have the modified image, but you need to get to accesses it as binary data. You can force the file content of the request to be treated as binary data by adding the attribute getasbinary to your cfhttp tag.

Working example:

<cfset imageURL ='https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/long_description.jpg'/>
<cfhttp method="get" getasbinary="yes" charset="utf-8" url="https://www.verexif.com/en/quitar.php" result="result">
    <cfhttpparam name="foto_url" type="formfield" value="#imageURL#">
</cfhttp>
<cfcontent variable="#result.Filecontent#" type="image/jpg" reset="true" />

Run it on TryCF.com

Related