2016-03-21 20 views
3

Ich versuche, die pdf-Datei von diesem Beispiel zu speichern:eine Blob-Datei im Dateisystem mit Cordova schreiben - Ionic

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

meinen Localdata. Ich fand, dass ich Dateiplugin benötige, aber ich weiß nicht, wie man die Blobdatei auf meinem System speichert. Ich habe versucht, diese zwei:

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

oder

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

aber ich kann nicht Speicher es. Wie kann ich das machen?

Antwort

4

Meine Lösung:

 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

ich diesen Ansatz verwenden, indem ich die Datei im iPhone finden kann. Wo soll gespeichert werden? – Tirias

+0

schauen Sie sich den App-Ordner auf dem Gerät mit XCode an – Mirko

Verwandte Themen