3

I'm having this issue with FILE_URI similar to the one raised in another post:

--> Cordova 2.8.1: camera.getPicture with photolibarary source on ios

I've tried using a simple code similar to the example provided in the Cordova docs.

HTML:

<head>
  <link rel="stylesheet" type="text/css" href="application.css">
  <script src="http://localhost/cordova.js"></script>
  <script src="/components/steroids-js/steroids.js"></script>
  <script src="application.js"></script>
</head>
<body>
    <div>
        <br>
        <button type="button" onclick="takePhoto()">Take photo</button>
        <br>
        <hr>
        <p>Image should appear below:</p>
        <img id="image" width="100%" height="100%" src="">
        <hr>
        <p>Image URI should appear below:</p>
        <p id="URI"></p>
    </div>
</body>
</html>

JS:

    function onCameraSuccess(imageURI) {
        document.getElementById('image').src = imageURI;
        document.getElementById('URI').innerHTML = imageURI;
    }

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

    function takePhoto() {
        navigator.camera.getPicture(onCameraSuccess, onCameraFail, { 
            quality: 50,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: 1,      // 0:Photo Library, 1:Camera, 2:Photo Album
            encodingType: 0,     // 0:JPG 1:PNG
            allowEdit: true,
            correctOrientation: true,
            saveToPhotoAlbum: true,     
        });
    }

I'm using the Cordova 3.1 API from AppGyver on iOS7. I tried using all the combinations of navigator.camera vs Camera, FILE_URI vs NATIVE_URI, and JPG vs PNG. None of these combinations worked. However I still get the right URI path (file:///var/mobile/Applications/…/tmp/cdvphoto024.jpg) but the image won't show when given this path as a source. It works when using DATA_URL on both CAMERA and PHOTOLIBRARY but this is of no use to me since I need to be able to store the path in LocalStorage and move the image file to a permanent location. Any idea how to solve this issue? Or maybe a workaround where I could use the saveToPhotoAlbum option, but then I don't know how to retrieve the path of that newly captured image without going through the getPicture manual selection again. Any idea? Thx

Community
  • 1
  • 1
MaT
  • 51
  • 6
  • Your code looks fine at first glance. Hmm... – islanddave Jul 04 '14 at 20:07
  • Does commenting out the steroids.js script help? Just trying to figure out what might be interfering. I've never used steroids.js in a cordova app, so not 100% what it might try to do here. – islanddave Jul 05 '14 at 01:45
  • No, commenting out steroids.js doesn't solve the pb. However I found a post where they seem to mention that the picture would show up when moving the image file to a local folder. Gonna try this out... https://muut.com/appgyver#!/steroids#cant-access-image-from-navi – MaT Jul 05 '14 at 15:04
  • So I almost managed to solved the problem by moving the image file to a local folder. But the image now appears very randomly. I raised a new question for this new issue: http://stackoverflow.com/questions/26371787/how-to-display-moved-pictures-from-phonegap-cordova-camera-api-under-angularjs – MaT Oct 22 '14 at 10:56

0 Answers0