使用 Cordova - Ionic 在文件系统中写入 blob 文件

Write a blob file in filesystem with Cordova - Ionic

我正在尝试保存此示例的 pdf 文件:

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

到我的本地数据。我发现我需要文件插件,但我不知道如何将 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
});

但我无法存储它。我该怎么做?

我的解决方案:

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

            });