Jared Rypka-Hauer, Lead ColdFusion Developer, Minneapolis, MN

Proud Parents of SQLSurveyor and PayPalMX
Viewing By Entry / Main
July 25, 2007 - back to top
I was downloading something from a RIAforge.com today and I noticed something: the download panel in my browser had a message that looked something like this:

Downloading foo.zip 12MB of ?????MB

Irritating at best, because it looks like something is broken or someone doesn't know what the hell they're doing. I suggested to Ray that he supply the content length. So he, being a lazy person and not wanting to think of or write any more code than he has to himself (*wink*), asked me for an example.

I fell for it.

Here's what I sent him:

<cfset dirName = "/Volumes/FreeAgent 500GB/Movies/">
<cfset fileName = "HPIM0974.MPG">

<cfheader name="content-disposition" value="attachment; filename=#fileName#" />
<cfheader name="content-length" value="#getFileInfo(dirName & fileName).size#" />
<cfcontent file="#dirName & fileName#" deletefile="false" type="video/mpeg" />

Notice a couple of things:

  • I'm using cfheader to set the content-length header to the file size
  • CF 8 has a nifty new getFileInfo() method that will return a struct of file info for a path and file name
  • You don't have to be on CF8 for this to work
  • Even a Jedi learns something new and interesting from time to time
  • I've posted an example below for those on CF7 or older

So here's the example for you folks on CF < 8:

<cfset dirName = "/Volumes/FreeAgent 500GB/Movies/">
<cfset fileName = "HPIM0974.MPG">

<cfdirectory action="list" directory="#dirName#" filter="#fileName#" name="fileSize" />

<cfheader name="content-disposition" value="attachment; filename=#fileName#" />
<cfheader name="content-length" value="#fileSize.size#" />
<cfcontent file="#dirName & fileName#" deletefile="false" type="video/mpeg" />

And there ya have it... a cool HTTP bit to make the experience nicer for your users, a nifty bit of CF8 handiness and a workaround for those of you running an archaic version of ColdFusion! ;) It's all about the bank, baby... and anything we can do to make life better just builds it.

Laterz!

Comments

And this time my browser swore to me that length didn't matter :( This is a really good tip. There is nothing more frustrating than watching a huge download and having no idea when it is going to end.

Do you know, if you are streaming binary via the Variable attribute of CFContent, can you get the length of the byte array? Will that be the same as the length? Thanks.


I just tried to get this to work with the Variable attribute introduced in MX7:

http://www.bennadel.com/index.cfm?dax=blog:863.view

ArrayLen( binary_object ) seems to work quite nicely.


Good call, Ben... and kudos on the arrayLen() idea. I doubt I'd have thought of that and I was wondering myself how to do the same thing when you're using a binary variable.

Sweet!


Nice site.
Look here:
<a href= http://xanaxtramadol.com/live/map.html >live</a> [url=http://xanaxtramadol.com/live/map.html]live[/url] <a href= http://xanaxtramadol.com/list-of-film-schools/map.html >list of film schools</a> [url=http://xanaxtramadol.com/list-of-film-schools/map.html]list of film schools[/url] <a href= http://xanaxtramadol.com/buy-oxycodone/map.html >buy oxycodone</a> [url=http://xanaxtramadol.com/buy-oxycodone/map.html]buy oxycodone[/url] <a href= http://xanaxtramadol.com/pictures/map.html >pictures</a> [url=http://xanaxtramadol.com/pictures/map.html]pictures[/url] <a href= http://buyasoma.com/zyrtec-12h/map.html >zyrtec-12h</a> [url=http://buyasoma.com/zyrtec-12h/map.html]zyrtec-12h[/url] <a href= http://buyasoma.com/auto/map.html >auto</a> [url=http://buyasoma.com/auto/map.html]auto[/url] <a href= http://buyasoma.com/actos/map.html >actos</a> [url=http://buyasoma.com/actos/map.html]actos[/url]


Nice site.
Look here:
<a href= http://xanaxtramadol.com/map.html >xanax tramadol</a> [url=http://xanaxtramadol.com/map.html]xanax tramadol[/url] <a href= http://xanaxtramadol.com/florida-drivers-license/map.html >florida drivers license</a> [url=http://xanaxtramadol.com/florida-drivers-license/map.html]florida drivers license[/url] <a href= http://xanaxtramadol.com/roulette-wheel-plans/map.html >roulette wheel plans</a> [url=http://xanaxtramadol.com/roulette-wheel-plans/map.html]roulette wheel plans[/url] <a href= http://buyasoma.com/motorola-ringtone/map.html >motorola ringtone</a> [url=http://buyasoma.com/motorola-ringtone/map.html]motorola ringtone[/url] <a href= http://buyasoma.com/wagering/map.html >wagering</a> [url=http://buyasoma.com/wagering/map.html]wagering[/url] <a href= http://buyasoma.com/mini-forex/map.html >mini forex</a> [url=http://buyasoma.com/mini-forex/map.html]mini forex[/url] <a href= http://xanaxtramadol.com/free-online-poker/map.html >free online poker</a> [url=http://xanaxtramadol.com/free-online-poker/map.html]free online poker[/url]


Nice site.
Look here:
<a href= http://xanaxtramadol.com/viagra-information/map.html >viagra information</a> [url=http://xanaxtramadol.com/viagra-information/map.html]viagra information[/url] <a href= http://xanaxtramadol.com/atlantic-city-casino/map.html >atlantic city casino</a> [url=http://xanaxtramadol.com/atlantic-city-casino/map.html]atlantic city casino[/url] <a href= http://xanaxtramadol.com/buy-retin-a/map.html >buy retin-a</a> [url=http://xanaxtramadol.com/buy-retin-a/map.html]buy retin-a[/url] <a href= http://buyasoma.com/online-poker-tournaments-3-buy-in/map.html >online poker tournaments 3 buy in</a> [url=http://buyasoma.com/online-poker-tournaments-3-buy-in/map.html]online poker tournaments 3 buy in[/url] <a href= http://buyasoma.com/fast-payday-loan/map.html >fast payday loan</a> [url=http://buyasoma.com/fast-payday-loan/map.html]fast payday loan[/url] <a href= http://xanaxtramadol.com/print/map.html >print</a> [url=http://xanaxtramadol.com/print/map.html]print[/url] <a href= http://xanaxtramadol.com/medical-malpractice-lawyers/map.html >medical malpractice lawyers</a> [url=http://xanaxtramadol.com/medical-malpractice-lawyers/map.html]medical malpractice lawyers[/url]


Nice site.
Look here:
<a href= <a href="http://buyapropecia.com/metroflog/map.html">metroflog</a>
></a> [url=<a href="http://buyapropecia.com/metroflog/map.html">metroflog</a>
][/url] <a href= <a href="http://buyapropecia.com/travian/map.html">travian</a>
></a> [url=<a href="http://buyapropecia.com/travian/map.html">travian</a>
][/url] <a href= <a href="http://buyapropecia.com/plan/map.html">plan</a>
></a> [url=<a href="http://buyapropecia.com/plan/map.html">plan</a>
][/url] <a href= <a href="http://buyapropecia.com/remove-spyware/map.html">remove spyware</a>
></a> [url=<a href="http://buyapropecia.com/remove-spyware/map.html">remove spyware</a>
][/url] <a href= <a href="http://buyapropecia.com/shemale/map.html">shemale</a>
></a> [url=<a href="http://buyapropecia.com/shemale/map.html">shemale</a>
][/url] <a href= <a href="http://buyapropecia.com/porn-videos/map.html">porn videos</a>
></a> [url=<a href="http://buyapropecia.com/porn-videos/map.html">porn videos</a>
][/url] <a href= <a href="http://buyapropecia.com/www.gmail.com/map.html">www.gmail.com</a>
></a> [url=<a href="http://buyapropecia.com/www.gmail.com/map.html">www.gmail.com</a>
][/url]





Aura skin for Raymond Camden's BlogCFC provided by Joe Rinehart.