Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a blob file in filesystem with Cordova - Ionic

I'm trying to save the pdf file of this example:

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

to my localData. I found i will need file plugin, but i don't know how to save the blob file to my system. I tried this two:

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

or

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

but i can't storage it. How can i do that?

like image 740
Steph8 Avatar asked Mar 21 '16 15:03

Steph8


1 Answers

My solution:

        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")

            });
like image 114
Steph8 Avatar answered Oct 27 '22 00:10

Steph8