David Powell created CB-9680:
--------------------------------

             Summary: Cordova File Transfer creates the empty file then stops
                 Key: CB-9680
                 URL: https://issues.apache.org/jira/browse/CB-9680
             Project: Apache Cordova
          Issue Type: Bug
          Components: Plugin File Transfer
    Affects Versions: 1.2.0
         Environment: Windows 8.1 Using ngCordova
            Reporter: David Powell


I have an object with file data I generate in a function that's structured like 
this:

fileData[0]['location'] = "/path/to/save/to/"
fileData[0][0] = "http://fileurl.com";
fileData[1]['location'] = "/path/to/save/to/"
fileData[1][0] = "http://fileurl.com";
fileData[2]['location'] = "/path/to/save/to/"
fileData[2][0] = "http://fileurl.com";
...
There's about 188 in total right now.

I run a second function that I pass the object to that starts from the bottom 
up, extracts the location, creates the directory, then passes data to a 
function to process the download. Once the download is complete it's supposed 
to remove the current item from the object, send the object back to the 
previous function and repeat until the object is empty.

function startDownload(fs, instlData) {
    delete instlData.__proto__;
    var currentLoc = getObjSize(instlData) - 1;
    var fileUrl = instlData[currentLoc][0];
    var fileLoc = instlData[currentLoc]['location'];

    var fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
    var filePath = fs.winpath + fileLoc + '/';

    fs.root.getDirectory("/" + fileLoc, { create: true }, function (dirEntry) {

        downloadFile(fileUrl, filePath, fileName, fs, instlData, currentLoc);

    }, function (err) { console.log(err); });


}
function downloadFile(fileUrl, filePath, fileName, fs, instlData, currentLoc) {

    var fileLoc = filePath + fileName;

    $cordovaFileTransfer.download(encodeURI(fileUrl), fileLoc, {}, true)
    .then(function (result) {
        console.log('success');
        console.log(instlData);
        delete instlData[currentLoc];
        startDownload(fs, instlData);
    }, function (err) {
        console.log('error');
        console.log(instlData);
        console.log(err);
        delete instlData[currentLoc];
        startDownload(fs, instlData)
    }, function (progress) {
        console.log('process');
        console.log(progress);
    });
}
}, false);

I'm running everything on deviceready per the docs. I've ran console.log() on 
the variables and all the urls are correct.

fs.root.getDirectory("/" + fileLoc, { create: true }, function (dirEntry) 
creates the directory as expected and 
$cordovaFileTransfer.download(encodeURI(fileUrl), fileLoc, {}, true) creates 
the empty placeholder file but it's never written to. As a matter of fact, 
nothing happens. No error, not process log, nothing. It doesn't even iterate to 
the next item... just stops.

If I provide anything that's not a URL (such as just removing "http://"; from 
the file url) it will iterate through all the items, create all the 
placeholders, and create all the directories. Obviously the file is empty 
because it's not a valid url.

I even tried the test file in the ngCordova example 
(http://cdn.wall-pix.net/albums/art-space/00030109.jpg)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to