Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a file from auto download url in coldfusion

I am trying to get a file from a auto 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 have specified the file type as CSV so I am able to get the file but file type can change. I tried CFHTTP.MIMETYPE to 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 is working for CSV and XML files. But I want it to work to Excel files also.

Please help. Thanks in advance.

like image 747
Beginner Avatar asked Feb 12 '15 07:02

Beginner


1 Answers

<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#">
like image 69
Deepak Kumar Padhy Avatar answered Oct 04 '22 09:10

Deepak Kumar Padhy