2
votes

In PhoneGap 3.3 android application using File-transfer plugin this is the body for getFile method

private JSONObject getFile(String baseURLstr, String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
        try {
            LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
            Filesystem fs = this.filesystemForURL(inputURL);
            if (fs == null) {
                throw new MalformedURLException("No installed handlers for this URL");
            }
            return fs.getFileForLocalURL(inputURL, path, options, directory);

        } catch (IllegalArgumentException e) {
            throw new MalformedURLException("Unrecognized filesystem URL");
        }

    }

Filesystem fs is always null when calling

fileSystem.root.getFile('text.txt', { create: true, exclusive: false }, function (fileEntry) {}, fail);

or

fileSystem.root.getDirectory('newDir', { create: true, exclusive: false }, function (parent) {}, fail);

Here is the javascript Code and the log result

downloadAgendaPage = function () {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    console.log("Emaish: FileSystem Requested");
    console.log("Emaish: fileStream.name = " + fileSystem.name);
    console.log("Emaish: fileStream.root.name = " + fileSystem.root.name);
    fileSystem.root.getFile("text.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    console.log("Emaish: File Gotten");
    var uri = encodeURI("http://****/data/MYOEB2013_Agenda.ics");
    console.log("Emaish: uri:" + uri);
    var sPath = fileEntry.fullPath.replace("text.txt", "Agenda.ics");
    console.log("Emaish: sPath:" + sPath);
    fileEntry.remove();
    var fileTransfer = new FileTransfer();
    fileTransfer.download(
        uri,
        sPath,
        function (theFile) {
            console.log("download complete: " + theFile.toURI());
            //showLink(theFile.toURI());
            alertify.alert("Agenda downloaded to " + theFile.toURI());
        },
        function (error) {
            console.log("download error source " + error.source);
            console.log("download error target " + error.target);
            console.log("upload error code: " + error.code);
        }
    );
}

Console.log Result

02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(59)] "Emaish: FileSystem Requested", source: file:///android_asset/www/js/agenda.js (59)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(60)] "Emaish: fileStream.name = persistent", source: file:///android_asset/www/js/agenda.js (60)
02-20 16:15:37.205: I/chromium(23491): [INFO:CONSOLE(61)] "Emaish: fileStream.root.name = ", source: file:///android_asset/www/js/agenda.js (61)

and therefore threw new MalformedURLException("No installed handlers for this URL");

1
add ur fileSystem in console.log and check what it showsDivesh Salian
i updated the question to show the javascript code and console.log resultAbou-Emish
to know it was working before upgrading from PhoneGap ver phonegap-2.9.1 to ver 3.3Abou-Emish
check if it is usefull link. It worked for meAkshay

1 Answers

0
votes

There problem was in the way i add the plugin and build my app, you need to build you application after adding the plugin in order for plugin js files to be copied correctly to the www folder and for cordova_plugins.js to be updated.