Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9819

navigator.camera.getPicture returns a base64 string, not a data url.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • cordova-plugin-camera

    Description

      When calling navigator.camera.getPicture with destinationType set to Camera.DestinationType.DATA_URL, the success function is called with the base64 encoded data. RFC2397 specified the data url should have the following format:

      data:[<mediatype>][;base64],<data>

      I would expect the data to be passed in this format, when a DATA_URL format is requested.

      The example in the README handles this "bug"

      navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
          destinationType: Camera.DestinationType.DATA_URL
      });
      
      function onSuccess(imageData) {
          var image = document.getElementById('myImage');
          image.src = "data:image/jpeg;base64," + imageData;
      }
      
      function onFail(message) {
          alert('Failed because: ' + message);
      }
      

      Instead I suggest the following options:

      • base64 encoded:
      navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
          destinationType: Camera.DestinationType.BASE64_ENCODED
      });
      
      function onSuccess(imageData) {
          var image = document.getElementById('myImage');
          image.src = "data:image/jpeg;base64," + imageData;
      }
      
      function onFail(message) {
          alert('Failed because: ' + message);
      }
      
      • data url:
      navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
          destinationType: Camera.DestinationType.DATA_URL
      });
      
      function onSuccess(imageData) {
          var image = document.getElementById('myImage');
          image.src = imageData;
      }
      
      function onFail(message) {
          alert('Failed because: ' + message);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            remcohaszing Remco Haszing
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: