In my previous post you saw how I wrote an uploader.js library for managing uploads to imgur.
Now the question is how to use it.
Here is a sample source code from a phonegap+jquery page.
The uploading happens in 2 steps. First, we choose the photo from the photolibrary. uploader.js sets up a callback_func to be invoked whenever the photo gets selected, it returns a 64 bit encoded string of the image. The function on the html side then sets up another function that take cares of the uploading process, setting up a second callback which takes care of any errors that might be raised. Thus it sort of sets up a nested callback.
Sample source code:
Now the question is how to use it.
Here is a sample source code from a phonegap+jquery page.
The uploading happens in 2 steps. First, we choose the photo from the photolibrary. uploader.js sets up a callback_func to be invoked whenever the photo gets selected, it returns a 64 bit encoded string of the image. The function on the html side then sets up another function that take cares of the uploading process, setting up a second callback which takes care of any errors that might be raised. Thus it sort of sets up a nested callback.
Sample source code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var pic_callback = function(image_data, message) { | |
if(message.length>1) {alert("Image selected ");} | |
var upload_callback = function(url, msg) { | |
if(url == null || url== undefined || url.length<1) { | |
alert("Failed to upload" + msg); | |
} else { | |
alert("Img Url " + url) | |
} | |
}; | |
Upload.upload(image_data, upload_callback); | |
} | |
</script> | |
<a href="#" onclick="Upload.getPhotoFromLibrary(pic_callback)">Select and upload Photo</a> |
0 comments
Post a Comment