Monaca Onsen UI Discord Chat Github Repo

navigator.camera.getPciture() returns "Not allowed to load local resource" error after success



  • navigator.camera.getPicture(
    function(success){
    // success = success.replace(“file://”,"");
    console.log(“Got photo: " + success);
    $(”#inPhotoSavePath").val(success);
    $("#inPhotoSaveImg").attr(“src”, success);
    $("#inPhotoSaveImg").show();
    function(failure){
    console.log("Photo failure: " + failure);
    },
    { quality: 10,
    saveToPhotoAlbum: true,
    targetWidth: 100,
    targetHeight: 100
    }
    )
    }
    After invoking the above getPicture function, it shows the following in console.log:

    Got photo: file:///data/user/0/mobi.monaca.debugger/cache/1655003948696.jpg
    Not allowed to load local resource: file:///data/user/0/mobi.monaca.debugger/cache/1655003948696.jpg

    I also tried to remove “file://” from the “success” by uncommenting the first line in the success function. The “Not allowed to load local resource…” error disappears, but the image cannot display on screen.

    Any ideas on how I can fix this or how should I access the image saved by the getPicture function?


  • administrators

    I’m not sure whether this is a quirk of Monaca Debugger (although I don’t think so) or to do with the library code you are using to load the picture. Maybe you can try one of the examples here and check if it works for your case:
    https://github.com/apache/cordova-plugin-camera#sample-take-pictures-select-pictures-from-the-picture-library-and-get-thumbnails-