2016-01-07 82 views
0

我花了整整一天的时间来解决这个问题。 文件被下载并存储在设备内存中,而不是未加载的。ngCordova插件zip与dendroid不兼容

// Url of file for download 
    var url = "http://exapmle/someUrl"; 

    // File names only 
    var file = "aaa.zip"; 

    $scope.contenutoDownload = function() {  
    // Save location 
    var targetPath = cordova.file.dataDirectory + file; 

    // Use cordovaFileTransfer to store the file in the device storage 
    $cordovaFileTransfer.download(url + file, targetPath, {}, true).then(function (result) { 

     console.log('File downloaded. ' + JSON.stringify(result)); 

     $cordovaZip 
      .unzip(
      result.nativeURL, 
      cordova.file.dataDirectory 
     ).then(function() { 

      console.log('cordovaZip success'); 
      //Delete zip file 
      if(cordova.platformId == 'ios') { 
       $cordovaFile.removeFile(cordova.file.tempDirectory,file); 
      } else { 
       $cordovaFile.removeFile(cordova.file.cacheDirectory,file); 
      } 

      }, function() { 

      console.log('cordovaZip error'); 

      }, function (progressEvent) { 

      console.log(progressEvent); 

      } 
     ); 

     }, function (error) { 

     console.log('Error with cordovaFileTransfer'); 

     }, function (progress) { 

     $timeout(function() { 
      $scope.downloadProgress = ((progress.loaded/progress.total) * 100) + '%'; 

     }); 

    }); 

    }; 

结果总是'cordovaZip错误',如果试图传递任何参数到函数(错误的一个)没有对象返回。

回答

0

看起来你的路径不正确

$cordovaZip 
     .unzip(
     result.nativeURL, 
     cordova.file.dataDirectory 
    ).then(function() { 

应该或可能是

$cordovaZip 
     .unzip(
     targetPath, 
     cordova.file.dataDirectory 
    ).then(function() { 

不知道什么nativeURL给我安慰所有这些了,看看有什么比赛 - 还以为nativeURL是一种方法nativeURL()