Skip to content

Instantly share code, notes, and snippets.

@wei-lee
Created November 16, 2011 10:52
Show Gist options
  • Save wei-lee/1369806 to your computer and use it in GitHub Desktop.
Save wei-lee/1369806 to your computer and use it in GitHub Desktop.
download file using $fh.file
var fileSrc = "http://example.com/test.pdf";
var parts = fileSrc.split("/");
var destFile = parts[parts.length - 1];
var progressListener = function(progress){
//progress value that is passed here is a float number between 0 and 1
//convert it to percentage
$('#download_progress').html('<p> current progress: ' + progress*100 + '%' + '</p>');
}
$fh.file(
{act:'download', src: fileSrc, dest: destFile, progressListener:progressListener},
function(path){
//open the downloaded file using $fh.webview
//$fh.webview can open most of the file formats on ios (pdf, doc, xls etc)
$fh.webview({act:'open', url: path});
},
function(err){
alert(err);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment