Railo Tip of the Week: Railo Resources

January 30, 2012 · By Christian Ready · 4 Comments

Since Railo 2.0, it is possible to use all different kinds of virtual file systems with all different kind of file related tags. Railo supports the following virtual file systems:

  • file (file:// or c:\ or /var/…) 
  • ram (ram://)
    Note that you can store the location for the RAM resource to any external cache or NoSQL key value store) 
  • ftp (ftp://username:password@ftpserver/) 
  • db (db://datasourcename:/) 
  • http (http://fileLocation) 
  • ZIP (zip://pathToFile!directory/file) 
  • TAR (tar://pathToFile!directory/file) 
  • TGZ (tgz://pathToFile!directory/file) 
  • S3 (s3://secret:access@amazonaws.com/bucket) 

When you want to use a given resource you can easily do it by using the following notation:

<cffile action="read" file="db://datasource/temp.txt" variable="susi">
<cfdirectory action="read" directory="ram://" name="susi">
<cfif fileExists("ftp://username:password@ftpServer/index.cfm")>...</cfif>

In addition you can easily define any resource as a mapping pointing to that resource. So you then can use these mappings inside your code.

Tags: Reference · Tips

4 responses so far ↓

  • 1 Chris Blackwell // Jan 31, 2012 at 12:01 AM

    For Amazon S3 the correct endpoint is s3.amazonaws.com (not amazonaws.com)
  • 2 Michael Offner // Feb 1, 2012 at 10:07 AM

    For S3 the best and most secure way is to define the credentials in the application.cfc as follows:
    this.s3.accessKeyId = "...";
    this.s3.awsSecretKey = "...";

    and then simply use s3://... in the code
  • 3 Mischa Sameli // Oct 9, 2012 at 3:10 PM

    As far as I know and according to the documentation, cfdirectory doesn't have an action read - at least your example throws an error.
  • 4 Paul // Dec 18, 2012 at 3:53 PM

    Each time I use the ram path in either a cf page or a railo directory mapping, I am getting a java null pointer exception. Has anyone run across this issue?

Leave a Comment

Leave this field empty: