Nifty little trick with fileRead and ColdFusion 10

This post is more than 2 years old.

ColdFusion 10 adds a nifty little feature to the VFS (Virtual File System) - support for FTP, HTTP, and ZIP. This means you can treat remote resources and zip files as if they were simple file systems. The docs don't go into great detail on this (and instead ask you to read the Apache Commons docs instead), but I discovered a simple, but really nice, good example of this.

Because fileRead supports http, if you want to quickly grab the contents of a URL, you can use it as I've done above. All it does is save you one line of code (compared to the normal cfhttp call followed by a set to grab the file contents), but it's handy!

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by RogerTheGeek posted on 5/21/2012 at 5:29 PM

Do you think this trick would be upward compatible in future CF versions of CF and Java? I always wonder whether a trick I use will come back to bite me in the ass a few years from now.

Comment 2 by Raymond Camden posted on 5/21/2012 at 5:50 PM

It's documented, so yes. :)

Comment 3 by Tyler Clendenin posted on 5/22/2012 at 1:21 AM

Pretty cool. I assume this performs a GET operation? From the Apache docs it doesn't look like it could be a versatile replacement for cfhttp.

Comment 4 by Raymond Camden posted on 5/22/2012 at 1:22 AM

Yep, it's a GET. Obviously it won't work if you have different needs.