Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resolveLocalFileSystemURI error code 5 windows phone 7 phonegap

I've tried implement this work around 1.capture a photo 2.Get the photo from it's saved place 3.Read photo as base64

I've followed this methodology:

var cameraOptions = {};
function capturePhoto() {
    console.log("capture photo");
    cameraOptions = { quality: 70, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA, saveToPhotoAlbum: true };
    doIt();
}
function doIt() {
    navigator.camera.getPicture(onCameraSuccess, onCameraFail, cameraOptions);
}
function onCameraSuccess(imageURI) {
    console.log("Camera Success");

    $('#MokhalfaPhotoLocation').val(imageURI);
    console.log("Image URI: " + imageURI);
    window.resolveLocalFileSystemURI(imageURI, onResolveImageSuccess, onFail); //get the file from the physical path...
}
  function onResolveImageSuccess(fileEntry) {
    fileEntry.file(gotFile, onFail);
}
function gotFile(file) {
    readDataUrl(file);
}
function readDataUrl(file) {
    console.log("read file as dataUrl");
    var reader = new FileReader();
    reader.onloadend = function (evt) {
        console.log("Read as data URL");
        window.localStorage.setItem("mokhalfaPhotoURL", evt.target.result);
 };
    reader.readAsDataURL(file);
}

this chain is worked fine till the CameraSuccess then it fail on the line

window.resolveLocalFileSystemURI(imageURI, onResolveImageSuccess, onFail);

it entered the onFail event With error code = 5

btw, this code worked fine on Android but the issue is here with Windows Phone 7 any one knows what is the problem?

like image 252
N0rA Avatar asked Oct 05 '22 22:10

N0rA


1 Answers

I recently came across this error. The solution is quite simple :)

function onCameraSuccess(imageURI) {
    console.log("Camera Success");

    $('#MokhalfaPhotoLocation').val(imageURI);
    console.log("Image URI: " + imageURI);
    window.resolveLocalFileSystemURI("//" + imageURI, onResolveImageSuccess, onFail); //get the file from the physical path...
}

If you alert the imageURI it should look like (/CachedImagePath/etcetc/), so the window.resolveLocalFileSystemURI doesnt know where to resolve so by prepending to the URI // it looks in the correct path.

Cheers, I will post this issue to their bug tracker

like image 175
DdD Avatar answered Oct 12 '22 02:10

DdD