文档指出,您只需设置destinationType 即可获得正确的结果。
module.controller('PictureCtrl', function($scope, $cordovaCamera) {
document.addEventListener("deviceready", function () {
var options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL, // <== HERE
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData; // <== HERE is how you create the actual string to send to server
}, function(err) {
// error
});
}, false);
});
我在这里有一个完整的工作示例https://github.com/aaronksaunders/dcww/blob/master/www/js/services.js#L39