tags:

views:

44

answers:

1

I am building a simple API that downloads files off a thirdparty CDN (Cloud Files). ColdFusion is currently successfully getting this file and by using CfContent and cfheader the file is available for download and the person who called the API.

The problem I am having is that these files are secure files so i cannot use a direct link to the CDN, and these files can range from 50MB-5GB. So because of these two issues, when I get the file from the CDN using CfHTTP, and then do this

<cfcontent type="MMIETYPE" variable="#CFHTTP.FileContent#" >

Im confused to as if ColdFusion is acting like a middle server where its getting the file in bits from the CDN and passing it to the user , OR is it downloading the entire file into memory and then streaming it to the user.

If its doing the latter, then how do I make it act as the middle server?

+3  A: 

Using cfhttp downloads the file. There is not much recourse for hiding the URI for the CDN without downloading the file and re-serving it to the end user.

Most end-users will not be able to tell where the file is located if you use the HTTP 301 or 302 status codes.

301 is a permanent redirect and 302 is a temporary redirect. The difference being some browsers cache 301's so that the user does not have to hit your server again if it requests the URI a second time.

You can do this simply

<cfheader statuscode="301" statustext="Moved permanently" />
<cfheader name="Location" value="#CDN_URI#" />
<cfabort />

or

<cfheader statuscode="302" statustext="Moved Temporarily" />
<cfheader name="Location" value="#CDN_URI#" />
<cfabort />

You can also use cflocation, which by default uses a 302, but can be made to use another status code using the statusCode attribute.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_j-l_04.html

Tyler Clendenin
In addition, using CFHTTP to download the file to your CF server and then CFContent to stream it back to the user ties up a thread for the duration of the download that ColdFusion would otherwise use to process requests. If your site experiences high load, you could potentially run out of threads.
Adam Tuttle
I would just use CFLOCATION, instead of writing the headers myself. Easier, less code, more readable, same result.
Ben Doom
Yeah, I actually have run into the issue of running out of threads.
Tyler Clendenin
Ahh Yes, Basically I was using CDN as a off site storage rather then a CDN. I Started to use S3 now and using cflocation and everything works perfectly!
Faisal Abid