Google App Engine's Virtual File System with OpenBD

ColdFusion, Internet, Web Development, BlueDragon

Working with the virutal file system on Google App Engine is fairly simple once you grasp the fact that all of your directories and files are really just BLOBs in the Google datastore.  If you have worked with binary data from a database before, then this should be quite easy for you.

Interaction with the filesystem is easily done through openBD's implementation of the cfdirectory and cffile tags.  You can CREATE and LIST directories from your VFS using the cfdirectory tag you know and love. 

The "tricky" part comes when you find that none of the files you have uploaded are web accessible.  In other words, you can upload to "/images" but you aren't going to be able to browse to "/images/mynewimage.jpg".   

One solution would be to create a .cfm template to take a URL query string and serve up the requested file from the VFS. 

 

For example:   getfile.cfm?f=mynewimage.jpg

Which you could then use as the SRC in an IMG tag. 

<img src="getfile.cfm?f=mynewimage.jpg" >

 

Where getfile.cfm might look like this:

<cffile action="readbinary" file="#ExpandPath('/images/' & url.f )#" variable="myFile">


<cfcontent type="#getMimeType(url.f)#" variable="#myFile#" reset="true" >

 

Note:  I created this method called getMimeType() for an example site:

<cffunction name="getMimeType" >
	<cfargument name="fileName" />
	<cfset var extension = ListLast(arguments.fileName,".") />
	<cfswitch expression=".#extension#">
		<cfcase value=".bmp"> <cfreturn "image/bmp"> </cfcase>
		<cfcase value=".css"> <cfreturn "text/css"> </cfcase>
		<cfcase value=".js"> <cfreturn "text/javascript"> </cfcase>
		<cfcase value=".jpg"> <cfreturn "image/jpeg"> </cfcase>
		<cfcase value=".jpeg"> <cfreturn "image/jpeg"> </cfcase>
		<cfcase value=".jpe"> <cfreturn "image/jpeg"> </cfcase>
		<cfcase value=".doc"> <cfreturn "application/msword"> </cfcase>
		<cfcase value=".docx"> <cfreturn "application/msword"> </cfcase>
		<cfcase value=".gif"> <cfreturn "image/gif"> </cfcase>
		<cfcase value=".gz"> <cfreturn "application/x-gzip"> </cfcase>
		<cfcase value=".htm"> <cfreturn "text/htm"> </cfcase>
		<cfcase value=".html"> <cfreturn "text/html"> </cfcase>
		<cfcase value=".ico"> <cfreturn "image/x-icon"> </cfcase>
		<cfcase value=".mov"> <cfreturn "video/quicktime"> </cfcase>
		<cfcase value=".mp3"> <cfreturn "audio/mpeg"> </cfcase>
		<cfcase value=".ppt"> <cfreturn "application/vnd.ms-powerpoint"> </cfcase>
		<cfcase value=".pps"> <cfreturn "application/vnd.ms-powerpoint"> </cfcase>
		<cfcase value=".tgz"> <cfreturn "application/x-compressed"> </cfcase>
		<cfcase value=".txt"> <cfreturn "text/plain"> </cfcase>
		<cfcase value=".wav"> <cfreturn "audio/x-wav"> </cfcase>
		<cfcase value=".wmv"> <cfreturn "video/x-ms-wmv"> </cfcase>
		<cfcase value=".xls"> <cfreturn "application/vnd.ms-excel"> </cfcase>
		<cfcase value=".xlsx"> <cfreturn "application/vnd.ms-excel"> </cfcase>
		<cfcase value=".zip"> <cfreturn "application/zip"> </cfcase>
		<cfcase value=".xml"> <cfreturn "application/xml"> </cfcase>
		<cfdefaultcase>
			<cfoutput>#extension#</cfoutput> FILE TYPE NOT SUPPORTED
			<cfabort>
		</cfdefaultcase>
	</cfswitch>

</cffunction>

tags:
cloud
Vince Bonfanti said:
 
Hi Aaron,

That's a great solution! There's another way to solve the problem that's built-in to GaeVFS as described here:

http://groups.google.com/group/openbd/msg/4882454e...

Vince
 
posted 75 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Fuelly