Apr 2 2009

Fun with mappings and resources: Part 1 ZIP and FTP

Posted by Mark Drew at 4:51 PM
1 comments
- Categories: railo

One of the many features that I find fantastic in Railo, and has been the topic of many a "after-work-down-the-pub" conversations, has been that of mappings.

How I have normally used mappings in the past has just been been to be able to access frameworks such as ModelGlue, Reactor and ColdSpring without having to put them in the webroot.

You can still do this with Railo of course, and even set that resource as trusted, but what I wanted to show was some of the really neat features of other types of mappings.

Railo supports the ability to create a mapping to other types of resources, such as FTP, HTTP, SFTP, Amazon's S3, ram and ZIP (and TAR and TGZ) filesystems.

A quick example of where this might be used is to move old logfiles to a zip file. this happens to everyone's server once in a while, you have a bunch of log files that need moving to zip, all you have to do is create a mapping to the zip file:
Virtual: /archive
Resource: zip:///Users/markdrew/wwwroot/mapping_examples/archive.zip

And then you have one line of code to move that log file to the archive:

    <cffile action="move" source="biglog.log" destination="/archive/biglog.log">

If you need to read it from the archive it is just as easy:

    <cffile action="read" file="/archive/biglog.log" variable="content">
    <cfdump eval=content>

There you go, same line without having to do cfzip or anything like that. Just move the item to that resource.

But wait! Lets say I want to move the logs off the server, and put them onto an FTP site. What do we do then? Well, we could change our code to use cfftp, or just change the mapping:

Virual: /archive
Resource: ftp://username:password@ftpsite.com/uploads/

Save it, the code does the same and voila, we are now saving it to an FTP site!  Nice!

Comments

Martijn van der Woud

Martijn van der Woud wrote on 04/02/09 8:53 PM

Nice feature! That way the storage medium is really transparent to the object that is moving/reading/copying/writing the file. The object will thus be less likely to require change so this will reduce maintenance.

Write your comment



(it will not be displayed)





Search Archives

Contribute


MD on Twitter

Categories

coldfusion cfeclipse personal apple cfconferences ukcfug model-glue webdev blogging cfunited coldspring railo presentations adobe cfobjective scotch on the rocks reactor lost jobs ajax eclipse flex model-glue frameworks max google podcast podcasting reference ask md fusebox getrailo spam cfml donations eventvalidation fusiondebug air blue dragon cloud development flying funny java microsoft music snipex tattoo tips apple aptana blog cfml derby eventguard graphic novels hosting itunes metrics open bluedragon rant wishlist apollo barcamp bolt cebit cfdevcon cfonwheels cfug codeshare codeswarm coldfusioncamp directing doh! firefox flash gadgets groovy jquery mdc mvc ooops pownce quack regex spry subversion tashr transfer webservices xml

Monthly Archives