Ionic: File download in custom directory in internal memory

i am trying to download the image from server and save in a directory/subdirectory/ , but file is downloading and saving at the some other place i am not finding it on my device
file path is : file:///data/data/com.XYZ.com/files/files/XYZ/ABC/3705db1c-5519-47f1-b716-c7c9324390aa_26183.jpeg

Here is the my code:

var directoryPath = "";
    $ionicPlatform.ready(function () {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
            function (fileSystem) {
                var directoryEntry = fileSystem.root; // to get root path to directory
                console.log("directoryEntry=");
                console.log(directoryEntry);
                directoryEntry.getDirectory("XYZ/", { create: true, exclusive: false },
                    function (Success) {
                        console.log("Directory Sucess"); console.log(Success);
                        Success.getDirectory("ABC/", { create: true, exclusive: false },
                            function (SubDirectory) {
                                console.log(SubDirectory);
                                directoryPath = SubDirectory.nativeURL;
                                if ($localStorage.ProfileImage !== undefined && $localStorage.ProfileURL !== "") {
                                    var ServerProfileFile = $localStorage.ProfileImage.substr($localStorage.ProfileImage.lastIndexOf('/') + 1);
                                    var localProfileFile = "";
                                    if ($localStorage.ProfileURL !== undefined && $localStorage.ProfileURL !== "") {
                                        localProfileFile = $localStorage.ProfileURL.substr($localStorage.ProfileURL.lastIndexOf('/') + 1);
                                    }
                                    if (ServerProfileFile !== localProfileFile) {
                                        // var fp = ;
                                        // console.log(fp);
                                        var fileTransfer = new FileTransfer();

                                        fileTransfer.download(encodeURI($localStorage.ProfileImage), directoryPath + ServerProfileFile,
                                            function (entry) {
                                                console.log(entry);
                                                console.log("download complete: " + entry.fullPath);
                                                $localStorage.ProfileURL = entry.nativeURL;
                                                ProfileImage.Image = $localStorage.ProfileURL;

                                            },
                                            function (error) {

                                                $localStorage.ProfileURL = $localStorage.ProfileImage;
                                                ProfileImage.Image = $localStorage.ProfileURL;

                                            });

                                    } else {
                                        $cordovaFile.checkFile(directoryPath, localProfileFile)
                                            .then(function (Filesuccess) {

                                                ProfileImage.Image = $localStorage.ProfileURL;

                                            }, function (error) {

                                                var fileTransfer = new FileTransfer();

                                                fileTransfer.download(encodeURI($localStorage.ProfileImage), directoryPath + ServerProfileFile,
                                                    function (entry) {
                                                        console.log(entry);
                                                        console.log("download complete: " + entry.fullPath);
                                                        $localStorage.ProfileURL = entry.nativeURL;
                                                        ProfileImage.Image = $localStorage.ProfileURL;

                                                    },
                                                    function (error) {
                                              $localStorage.ProfileURL = $localStorage.ProfileImage;
                                                        ProfileImage.Image = $localStorage.ProfileURL;

                                                    });

                                            });

                                    }

                                }
                                $scope.$apply();

                            },
                            function (SubErrror) {
                                console.log("Directory Fail SubErrror"); console.log(SubErrror);
                            });

                    }, function (error) {
                        console.log("Directory Fail"); console.log(error);
                    });
            },
            function () {
                console.log("error getting LocalFileSystem");
            });
    });

Please help me into this i am not getting any solution.

1 Like

it was working for me earlier but recently i update ionic and install ionic-material then its not working.
Please help me into this tell me where i am doing wrong, or is any issue with update.