Download the public beta of ColdFusion Splendor from here
Yesterday I posted an example of how to take picture and upload it to CF server in a mobile app using CFMobile features. One of the APIs this example used was to upload file to CF server -
( , , , ,
onFileUpload is a success callback function and uploadError is an error callback function. To this Sean Corfield tweeted at me following question -
@ram_kulkarni surprised cfclient.file.upload needs callbacks - isn't the point of cfclient to avoid writing those?
I was going to reply to Sean directly but then thought that others might have the same question, so decided to answer it in this blog post.
So yes, one of the ways cfclient tries to simplify writing code for mobile applications is by providing synchronous function access to some of the asynchronous PhoneGap APIs. However it does not do so in two cases - 1. function call leaves device boundary 2. function requires event based processing.
File upload APIs falls in the first category - it makes call to a server and you certainly don't want the mobile application to get blocked till it gets response from the server.
Example of function in the second category is cfclient.geolocation.watchPosition, which i used in my post 'CFMobile Example – Using Geolocation APIs in ColdFusion Splendor'. This function takes action based on an event - when position changes, so it takes callback function as an argument.
But many APIs for Database, Contacts, File, Camera need not be asynchronous. If you develop standalone desktop applications, do you access database asynchronously ? I guess, most likely not.
Specifically regarding file upload function, we debated if we should include it in cfclient, because it is vary similar to the actual PhoneGap file upload function. And we decided to include it because - 1. for the sake of completeness and 2. you can get code assist for it in Thunder.