I am building an Ionic app with camera plugin. The problem that I need to solve is following as below:
- Execute Ionic App
- Open the camera via
cordova-plugin-camera Take a photo and retrieve data with
FILE_URI, but in step 3, when I receive the data with URI, the file path is like this:file:///sdcard/emulated/0/..../142312321.jpgSo I save this uri to
$scope.photo_uriand set the<img/>tag to<img src="{{photo_uri}} />
But no photo displayed. How can I solve this?
The codes are following as below:
$scope.onTakePhoto = function() {
if (typeof navigator.camera == 'undefined'){
alert("We'r sorry! Please try again on your Phone.^_^");
return;
}
var options = {
quality : 75,
destinationType : Camera.DestinationType.NATIVE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function (imageUri) {
//try{
var id = 'P_' + (new Date()).Format('MM_dd') + '_' + ($scope.photoList.length + 1);
//var data = "data:image/jpeg;base64," + imageData;
var date = (new Date()).Format('yyyy-MM-dd hh:mm P');
var name = 'PM_IMG_' + (new Date()).Format('yyyyMMddhhmmss') + '.jpg';
var location = gMyLocation.getData();
var uri = $scope.folder.uri;
window.resolveLocalFileSystemURL(imageUri, function(fileEntry) {
//If this doesn't work
$scope.camera_image_data.image = fileEntry.nativeURL;
console.log($scope.camera_image_data.image);
//Try this
//var image = document.getElementById('myImage');
//image.src = fileEntry.nativeURL;
});
//$scope.camera_image_data.image = 'cdv' + imageUri;
//alert('DataURI : '+ imageUri);
//createPhotoFile($scope.folder.uri, name, data, true);
//movePhotoFile(imageUri, uri, name);
var sPhoto = new PhotoObj(id,name,date,location,uri);
$scope.photoList.push(sPhoto);
//alert("PATH : " + $scope.photoList[0].uri +'\n'+
//'NAME : ' + $scope.photoList[0].name);
}, function (err) {
// error
console.log(err);
});
};