How do I download a file using phonegap 1.5 (Cordova) for BlackBerry and mango windows?

I am writing a phonegap application that needs to download a file (pdf, doc, txt).
I am using phonegap 1.5.0 i.e. Cordova 1.5.0.js.

I looked into the handset api at
http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileTransfer
and is trying to use the FileTransfer upload method. the following code i am using:

save: function (fileName, fileType, url) {
    documentsaver.fileName = fileName;
    documentsaver.fileType = fileType;
    documentsaver.url = url;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess, fail);

    function fail(event) {
        jqmSimpleMessage('Error Code ' + event.target.error.code);
    }

    function fsSuccess(fileSystem) {
        documentsaver.directoryEntry = fileSystem.root;

        //Creating directory in which document should be saved if it does not exist
        documentsaver.directoryEntry.getDirectory(documentsaver.directoryName, { create: true, exclusive: false }, dirSuccess, fail);

        function dirSuccess(parent) {
            console.log('Directory Created at '+parent.fullPath+' with name '+parent.name);
            //Moving directoryEntry reference to newly created directory
            documentsaver.directoryEntry = parent;

            //Creating file which will be written
            var completeFileName = documentsaver.fileName + '.' + documentsaver.fileType;
            console.log('completeFileName === >' + completeFileName );
            var filePath = documentsaver.directoryEntry.fullPath + '/' + completeFileName;
            console.log('filePath === >' + filePath );

            var fileTransfer = new FileTransfer();
            fileTransfer.download(
                    url,
                    filePath,
                    function(entry) {
                        console.log("download complete: " + entry.fullPath);
                    },
                    function(error) {
                        console.log("download error source " + error.source);
                        console.log("download error target " + error.target);
                        console.log("upload error code" + error.code);
                    }
                );
        }

      



filename: the name of the file I am saving.
fileType: fileType, that is, pdf or doc or png.
url: link to a real resource.

Below is the console log when I run it on a Windows emulator:

Log: "This is the
Stream directory (0xf0a01c6) exited with code 0 (0x0).
Log: "filePath ===> / JarusDocuments / Personal Auto Application.pdf"
Stream '' (0xff001f6) exited with code 0 (0x0).
Log: "Directory created in / JarusDocuments named JarusDocuments"
Log: "Error in success callback: File11 = Object does not support property or method" load "

Stream" (0xe3201b6) exited with code 0 (0x0).
Stream "(0xf18014e) exited with code 0 (0x0).
Log: "completeFileName ===> Personal Auto Application.pdf"
Stream '' (0xf1c01de) exited with code 0 (0x0).

FileTransfer is said to not support upload method. Although the magazine already says that it can create all the directories I want.

+3


source to share


1 answer


In Phonegap 1.5 for WP7, the FileTransfer object is not available for download (download only). Version 1.6, however, claims to be able to do this (you can read it for yourself in the release blog post here )



+1


source







All Articles