【问题标题】:Write a blob file in filesystem with Cordova - Ionic使用 Cordova 在文件系统中写入 blob 文件 - Ionic
【发布时间】:2016-07-08 05:20:54
【问题描述】:

我正在尝试保存此示例的 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
});

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

【问题讨论】:

    标签: cordova pdf ionic-framework blob makepdf


    【解决方案1】:

    我的解决方案:

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

    【讨论】:

    • 我正在使用这种方法,因为我在 iPhone 中找不到文件。应该保存在哪里?
    • 使用 XCode 查看设备上的 app 文件夹
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2017-12-16
    • 2018-08-13
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多