0

Someone know how to download an file (pdf) using phonegap for android

I already looked a lot of tutorial but any of them work for me.

THank you.

QuickFix
  • 11,661
  • 2
  • 38
  • 50
user3214262
  • 91
  • 1
  • 1
  • 8
  • 2
    did u checked [this](http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer) – Divesh Salian Feb 24 '14 at 07:39
  • check this- http://stackoverflow.com/questions/21577230/phonegap-save-image-from-url-into-device-photo-gallery/21579097#21579097 – Suhas Gosavi Feb 24 '14 at 10:08
  • I'm trying to follow your post, but I getting confused, in which file the I need to save you code example ? I'm really need with phonegap – user3214262 Feb 25 '14 at 07:57

1 Answers1

0

You will need to make use of the FileTransfer object here: http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer.

With this, you will need to call the download method - passing in the file URI, destination and success/error callbacks.

I.e., if I want to download a PDF, you could do so as follows:

var win = function(r) {
    console.log("Should not be called.");
}

var fail = function(error) {
    // error.code == FileTransferError.ABORT_ERR
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

var ft = new FileTransfer();

ft.download(
    'http://www.mydomain.com/mypdfdoc.pdf',
    myURI, // you can obtain this via a window.requestFileSystem(...)
    function (fileEntry) {
        // do something with fileEntry
    },
    function (error) {
        // handle error appropriately
    });
keldar
  • 6,152
  • 10
  • 52
  • 82