2016-03-21 40 views
3

我試圖挽救這個例子中的PDF文件:寫文件系統中的BLOB文件,科爾多瓦 - 離子

http://gonehybrid.com/how-to-create-and-display-a-pdf-file-in-your-ionic-app/

我localData。我發現我需要文件插件,但我不知道如何將Blob文件保存到我的系統。我想這二:

$cordovaFile.writeFile(cordova.file.externalCacheDirectory, "file.pdf", pdf, true) 
.then(function(success) { 
    console.log("file creato") 
}, function(error) { 
    console.log("errore creazione file") 
}); 

$cordovaFile.createFile(cordova.file.dataDirectory, $scope.pdfUrl, true) 
.then(function (success) { 
    // success 
}, function (error) { 
    // error 
}); 

但我不能存儲它。我怎樣才能做到這一點?

回答

4

我的解決辦法:

 var pathFile = ""; 
     var fileName = "report.pdf"; 
     var contentFile = blob; 

     if (ionic.Platform.isIOS()) { 
      pathFile = cordova.file.documentsDirectory 
     } else { 
      pathFile = cordova.file.externalDataDirectory 
     } 

     $cordovaFile.writeFile(pathFile, fileName, contentFile, true) 
      .then(function(success) { 
       //success 
      }, function(error) { 

       alert("error in the report creation") 

      }); 
+0

我使用這種方法,由我找不到在iPhone上的文件。被保存的地方在哪裏? – Tirias

+0

使用XCode查看設備上的應用程序文件夾 – Mirko