离子/科尔多瓦。将图像保存到照片库

时间:2015-12-08 12:01:16

标签: angularjs cordova ionic-framework ionic cordova-plugins

我有外部PNG图片的网址。我想直接下载到Camera Roll(iOS)或Photo Gallery(Android)。我如何用Ionic

来管理它

1 个答案:

答案 0 :(得分:0)

试试这个:

cordova plugin add org.apache.cordova.file-transfer

cordova plugin add cordova-plugin-file

在索引中添加文件链接。

 <script src="js/ng-cordova.js"></script>
 <script src="js/FileTransferController.js"></script>
控制器中的

$scope.downloadFile = function() {
        var url = "http://your_ip_address/images/my.png";
        var filename = url.split("/").pop();
        alert(filename);
        var targetPath = cordova.file.externalRootDirectory + filename;
        var trustHosts = true
        var options = {};
        alert(cordova.file.externalRootDirectory);
        $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
            .then(function(result) {
                // Success!
                alert(JSON.stringify(result));
            }, function(error) {
                // Error
                alert(JSON.stringify(error));
            }, function (progress) {
                $timeout(function () {
                    $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                })
            });
    }

来自HERE

希望它对某人有所帮助。

相关问题