2016-01-07 35 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()