0

I am storing an image through native code in the following directory

"/var/mobile/Applications/74299C07-49B8-42C4-8C8B-141932C73E28/Documents/userSignature.png"

And then, I am loading the image to a an image view in js/html in the following manner, However it's unable to get the file.

window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, TRAINING_SIGNATURE.onFileSystemSuccess, TRAINING_SIGNATURE.fail);

onFileSystemSuccess: function(fileSystem){
    var filePath = this._signatureFilePath;

    var divId = "trainingSignatureImg";
    loadImageFromFile(fileSystem,filePath, function onReceivedImageObject(result){
        document.getElementById(divId).src = result;
    });

}

function loadImageFromFile(fileSystem, filePath, onReceivedImageObject){

    fileSystem.root.getFile(filePath, {create : false}, 
        function gotFileEntry(fileEntry){
            fileEntry.file(function gotFile(file){
                var reader = new FileReader();
                reader.onloadend = function(evt) {
                    onReceivedImageObject(evt.target.result);
                };
                reader.readAsDataURL(file);

        }, function fail(evt){
            alert("Failed to read file "+evt);
        });

    }, function fail(evt){
        alert("Failed to get file "+evt);
    });

}

Preference added in iOS config

"<preference name="iosPersistentFileLocation" value="Library" />"

Can someone point out to me what I am missing? However, it works in Android, the only difference is that I have to add File System permission in Android manifest.

Error: Failed to get file... 
Arun Abraham
  • 4,011
  • 14
  • 54
  • 75

1 Answers1

1

I was using the absolute path of the image instead of the relative path.

Arun Abraham
  • 4,011
  • 14
  • 54
  • 75