Coldfusion CFHTTP Issues with Indirect Image URLs

I have a script that goes through an XML document and retrieves the URLs of images, and continues to load 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 occurs when the URL variable "qTempImageData.url" is something that does not end in the image extension, for example .png or .jpg ... for example:

 http://img.agentaccount.com/f6ec41e07261cec1b9e120fc0186b1cf7e583d66 

This URL serves to display the image, and you can see that the image exists, but I can not track it to any URL that the file itself will host, and thus download it, as usual, using the above CFHTTP commands ...

Is there any way to account for โ€œservedโ€ images like what is specified in the URL variable?

~ Eliseo

+4
source share
1 answer

In the case of the URL you provided, any file name associated with the file has disappeared, so you need to create a new name.

If your problem is that you need information about the extension to save and subsequently maintain the file, then one approach is to look at the content header that you will return and use it to determine the file extension.

So, if the file name defined by your ListLast () call does not end with .jpg, .jpeg, .png, etc. then read oHttp.responseHeader ["content-type"], which will be image / jpeg or image / png to determine the file extension to add.

+3
source

Source: https://habr.com/ru/post/1444521/


All Articles