AppGyver android show captured Image Issue

140 Views Asked by At

I need to show captured image in my ApGyver steroids app. I capture the image and then try to set the src in my image. But it gives me error of No local resource allowed:

I'm capturing the image this way:

            var options = {
                quality: 50,
                targetWidth: 300,
                targetHeight: 300,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.CAMERA, // Camera.PictureSourceType.PHOTOLIBRARY
                allowEdit: false,
                encodingType: Camera.EncodingType.JPEG,
                popoverOptions: CameraPopoverOptions,
                saveToPhotoAlbum: true,
                limit: 1
            };
            // capture callback
            var captureSuccess = function(mediaFiles) {
                var i, path, len;
                console.log(mediaFiles);
                for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                    path = mediaFiles[i].localURL;
                    // do something interesting with the file
                }
                if (switched) {
                    $scope.post.media = []
                }
                $scope.post.media.length = 1;
                $scope.post.fileUrl = path;
                setActionType('image');
                $scope.isBusy = false;
                console.log('hello' + path);
            };

            // capture error callback
            var captureError = function(error) {
                navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
            };

            // start image capture
            navigator.device.capture.captureImage(captureSuccess, captureError, options);
1

There are 1 best solutions below

1
KAUSHAL J. SATHWARA On

try this code for capture and upload image. and in your index.html link cordova.js and add camera plugin ok. and still any problem message me.

function capturePhoto() {
         navigator.camera.getPicture(uploadPhoto, onFail, {
         quality: 50, 
         // allowEdit: true,
         correctOrientation: true,
         destinationType: Camera.DestinationType.FILE_URL,
         // destinationType: Camera.DestinationType.DATA_URL
         sourceType: Camera.PictureSourceType.CAMERA
     });
    }

    function onFail(message) {
    // alert('Failed because: ' + message);
    }

    function uploadPhoto(imageURI){
    console.log(imageURI);

    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var ft = new FileTransfer();
    ft.upload(imageURI, encodeURI("http://XYZ/uploadimg?user_id="+UserId+""),  winGallary, fail, options);
    console.log(ft.upload);
    }

    function winGallary(rGallary) {
        console.log("Code = " + rGallary.responseCode);
        console.log("Response = " + rGallary.response);
        console.log("Sent = " + rGallary.bytesSent);

    }

    function fail(error) {
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
    }