2013-02-25 20 views
5

tôi đã cố gắng thực hiện công việc này khoảng 1. chụp một bức ảnh 2. Nhận ảnh từ nó được lưu nơi 3. đọc ảnh dưới dạng base64resolveLocalFileSystemURI mã lỗi 5 windows phone 7 PhoneGap

tôi đã theo phương pháp này:

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); 
} 

chuỗi này làm việc tốt cho đến khi CameraSuccess sau đó nó thất bại trên dòng

window.resolveLocalFileSystemURI(imageURI, onResolveImageSuccess, onFail); 

nó bước vào sự kiện onFail Với mã lỗi = 5

btw, mã này hoạt động tốt trên Android nhưng vấn đề là ở đây với Windows Phone 7 bất kỳ ai biết vấn đề là gì?

Trả lời

4

Gần đây, tôi đã gặp phải lỗi này. Giải pháp là khá đơn giản :)

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... 
} 

Nếu bạn cảnh báo imageURI nó sẽ giống như (/ CachedImagePath/etcetc /), do đó window.resolveLocalFileSystemURI doesnt biết được nơi để giải quyết như vậy bởi prepending để URI // nó nhìn vào đường dẫn chính xác.

Chúc mừng, tôi sẽ đăng sự cố này lên trình theo dõi lỗi của họ

0

Vấn đề này đã được giải quyết. Xem "https://issues.apache.org/jira/browse/CB-2736". Tuy nhiên, trên điện thoại Windows 8 của tôi, tôi không thể truy cập tệp ảnh để hiển thị trong thẻ HTML IMG. Tôi đã thử fileEntry.fullPath, fileEntry.toURL() và fileEntry.toNativeURL().

0

bạn nên thử một cái gì đó như thế này

$window.resolveLocalFileSystemURL("file://" + videoURI, function (fileEntry) { 
    console.log('Success: '+fileEntry.name); 
    fileEntry.getMetadata(function(metadata) { 
     if(metadata.size>20971520){ 
      $ionicPopup.alert({ 
       template: '<h5>Lo sentimos <i class="icon ion-sad-outline"></i> , el video sobre pasa el limite de peso</h5>', 
       title: 'Limite de peso', 
      }); 
     }else{ 

     } 
    }); 
}, function (err) { 
     console.log(err); 
});