I am using ionic and the ngCordova camera plugin to invoke my camera and I am getting my image in base64 formate I dont need to save the image but I need the Image to be sent to serve not as base64. I need to send it as a file formate is there any way to send the image as file to serve my backed is c#.
This is my html looks like
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}">
<img ng-show="imgURI === undefined" ng-src="http://placehold.it/250x250">
<button class="button" ng-click="takePicture()">Take Picture</button>
My app.js file
$scope.takePicture = function(){
var options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 250,
targetHeight: 250,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
console.log(imageData);
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
};
}, false);
In my imageData i am have the base64 value is there a way to convert $scope.imgURI into file so that i will be able to send my image to serve.
Why don't you use Camera.DestinationType.FILE_URI
, instead of Camera.DestinationType.DATA_URL
, for destinationType?
That way, you'd get a file on your device filesystem; then I suppose it should be easy to upload that file to your server...
Then, if you don't need that file on your device anymore, you can remove it.
If you instead prefer handling base64, you could check angular-base64-upload module, which uploads base64 data to a server...