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

(browser) Problem using cordova.file.dataDirectory

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 6.5.0
    • Fix Version/s: None
    • Component/s: cordova-plugin-file
    • Labels:
      None

      Description

      I'm using the file pluging togheter with the file transfer.

      cordova.file.dataDirectory contains 'filesystem:file:///persistent/' and this does not look to be correct.
      The download will fail here, but seems to be failing in the file plugin.

      var fileTransfer = new FileTransfer();
      
      fileTransfer.download(
      	encodeURI('source url'),
      	targetUrl, // cordova.file.dataDirectory + 'file.txt'
      	function(entry) {
      		// success
      	},
      	function(error) {
      		$log.log("Download error source " + error.source);
      		$log.log("Download error target " + error.target);
      		$log.log("Download error code" + error.code);
      	},
      	false
      );

      I solved this by doing something like:

      if($cordovaDevice.getPlatform() !== 'browser') {
      	targetUrl = cordova.file.externalDataDirectory + 'media/' + filename;
      }
      else {
      	// removed the media folder so that I do not have to create a directory, as it is not automatically created on the browser platform
      	targetUrl = 'filesystem:'+ window.location.origin + '/persistent/' + filename;
      }
      

      Remark: for some reson, this works for 127.0.0.1, but not for localhost.

      Plugins:
      cordova-plugin-admobpro 2.28.3 "AdMob Plugin Pro"
      cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab"
      cordova-plugin-buildinfo 1.1.0 "BuildInfo"
      cordova-plugin-compat 1.1.0 "Compat"
      cordova-plugin-device 1.1.6 "Device"
      cordova-plugin-extension 1.5.1 "Cordova Plugin Extension"
      cordova-plugin-file 4.3.2 "File"
      cordova-plugin-file-transfer 1.6.2 "File Transfer"
      cordova-plugin-inappbrowser 1.7.0 "InAppBrowser"
      cordova-plugin-media 3.0.0 "Media"
      cordova-plugin-music-controls 1.4.1 "MusicControls"
      cordova-plugin-whitelist 1.3.2 "Whitelist"
      cordova-plugin-x-toast 2.6.0 "Toast"
      cordova-sqlite-storage 2.0.3 "Cordova sqlite storage plugin"
      cordova-universal-links-plugin 1.2.1 "Universal Links Plugin"

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dellagustin@gmail.com Guilherme Dellagustin
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: