With OpenBD on Google App engine it can be a little tricky to access files if you need to upload files from a remote location. Unless you add these assets to your project before you deploy the application you cant access the files uploaded. Files that are uploaded go into a Virtual file system that can't be directly accessed. http://myapp.appspot.com/uploadedimages/sample.jpg wont load even if you have saved the file using expandPatch('images') which would work on any normal server setup.
Now you might first ask why you want to do this as I was asked when ( about a year ago now ) I tried to accomplish this. Lets say I have a app that users create profiles and they can upload a image of them self for an avatar how do I then reference that image?
Well it's actually really easy. When you set up GAE open the web.xml file.
You can see I made an extra mapping from default called /files this is where I will upload my files to. and /files will be browse able listing the files for download/access.
I made a simple demo which you can try out here: http://websheppaul.appspot.com
File size is limited to about 5meg and will fail over that. Not all mimetypes are supported so if you want to try it upload a jpg. I have a cron job cleaning the uploads once every few days.
If you are not sure on whats involved in setting up OpenBD on Google App engine check out this post: http://blog.kukiel.net/2009/09/coldfusion-on-google-app-engine-with.html In less then 5 minutes this walk through will show you how to deploy an app to GAE.
Here is the code:
upload.cfm
index.cfm
Storing the image in the blobstore, and serving via the "high performance image serving system" (http://code.google.com/appengine/docs/java/images/overview.html) would be a better bet for user-uploaded avatar type operations...
ReplyDelete(Not sure how that's done in BD though...)
when i try your demo page in Firefox 3.6.13, I get an error page:
ReplyDelete"The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept
cookies."
It displays fine when I view it in Chrome.
Fantastic post Paul thank you so much.
ReplyDelete@Geoff, as far as I'm aware writing blob's to google's datastore is not possible with OpenBD.
@Geoff perhaps but I'm assuming the VFS is probably using this anyway. Also OpenBD has image manipulation inbuilt. But it also loosk good.
ReplyDelete@Jay if you read in binary and put it in a cfc as a property you could then store the cfc as an object in the datastore. In theory it would work. I might try it.
can you give the file openBDcmf 5M!I can't down it!thanks !My email is y2w2h2@gmail.com
ReplyDelete@Gitar I'm not sure what your asking?
ReplyDelete