Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9680

Cordova File Transfer creates the empty file then stops

VotersWatch issueWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      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)

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            dcp3450 David Powell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment