I have a script which goes through an XML document and extracts the image URLs, and proceeds to download them using CFHTTP as follows:
<cfhttp method="get" url="#qTempImageData.url#" result="oHttp">
<cfhttpparam type="CGI" name="http_referer" value="http://www.realestate.com.au" encoded="false" />
</cfhttp>
<cfimage action="write" destination="#APPLICATION.vTempPath#properties\#ListLast(qTempImageData.url, '/')#" source="#oHttp.FileContent.toByteArray()#" overwrite="yes" />
The problem arises when the URL variable “qTempImageData.url” is something that doesn’t terminate in an image extension like .png or .jpg… for example:
http://img.agentaccount.com/f6ec41e07261cec1b9e120fc0186b1cf7e583d66
This URL does serve the image up and one can see that an image exists, but I am unable to trace it to any URL that would host the file itself, and thus download it as I normally would with the above CFHTTP command…
Is there any way that I can account for “served” images like the one in the URL variable?
~ Eliseo
In the case of the URL you list, whatever filename was once associated with the file is gone, so you’ll need to create a new name.
If your problem is that you need the extension information in order to save and then serve the file, then one approach would be to look at the content-type header you get back and use that to determine the file extension.
So, if the filename as determined by your ListLast() call doesn’t end in .jpg, .jpeg, .png etc, then read the oHttp.responseHeader[“content-type”] which will be image/jpeg or image/png to determine the file extension to add.