2016-11-06 106 views
0

我試圖使用zip plugin將文件從www文件夾解壓縮到外部位置。cordova從www文件夾中解壓縮文件

當應用程序啓動時,我將外部數據目錄分配給變量folder

window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (folder) { 
       $filex.folder= folder; 
}); 

然後我打電話給dataUnzip。

dataUnzip:function(){ 
     var wwwPath = window.location.pathname; 
     var basePath = 'file://'+ wwwPath.substring(0,wwwPath.length-10); 
     window.resolveLocalFileSystemURL(basePath+'ex.zip', 
     function(fileDB){ 
      alert('success! database was found') 
       unzipFiles(fileDB); 

     }, 
     function(){ 
      alert('failure! database was not found') 
     }); 

     function unzipFiles(fileDB){ 
      zip.unzip(fileDB,$filex.folder.nativeURL + "", 
       function (a) { 
        alert('Zip decompressed successfully' + a); 
       } 
      ); 
     } 
} 

但我總是得到輸出爲Zip decompressed successfully -1-1意味着解壓縮失敗。如果我從外部位置解壓縮.zip如externalDataDirectory。但我想解壓縮文件存在於www目錄中。 是否有任何方式來獲取描述性錯誤?而不是-1.and什麼可能是解壓縮失敗的原因?

這裏是WWW文件夾的截圖

enter image description here

回答

0

Read here for documentation about file permissions etc

外部數據目錄並非適用於所有平臺,什麼平臺你在測試嗎?

你不能只存儲解壓到你的應用程序目錄中的文件嗎?

否則,您可能需要爲每個平臺使用不同的位置並使用合併文件夾。

+0

以及我專注於android.the問題是不是與外部數據目錄。我可以解壓縮任何外部目錄。問題它不工作時,我試圖從www文件夾解壓到external.basically問題是與www文件夾 –

+0

我想你將需要複製從www文件夾的zip到外部數據目錄,並從那裏解壓縮。我想這是試圖寫入一些東西到WWW文件夾,因爲它沒有寫入WWW文件夾的權限。 –