Get file with automatic download URL in coldfusion

I am trying to get a file from an automatic download URL using cfhttp. I am using the following code:

<cfhttp method="get" url="http://www.example.com/getfile" path="E:/" file="abc.csv">

In this case, I specified the file type as CSV, so I can get the file, but the file type can change. I tried CFHTTP.MIMETYPEto get the file type and use like this:

<cfhttp method="get" url="http://www.example.com/getfile">
<cffile action="write" file="E:/abc.#listLast(cfhttp.MIMETYPE,'/')#" output="#cfhttp.FileContent#">

And this works for CSV and XML files. But I want it to work with Excel files too.

Please, help. Thanks in advance.

+4
source share
1 answer
<cfhttp method="get" url="http://www.example.com/getfile">
<cfset fileName = listlast(cfhttp["responseHeader"]["content-disposition"],";=")>
<cffile action="write" file="E:/abc.#fileName#" output="#cfhttp.FileContent#">
+4
source

All Articles