After trying for several hours, I decided to ask for community help on this issue. I am developing an Ionic app and I need to upload an image from Cordova Camera to Cloudinary. Now we can do it either by clicking the image from the camera (which loads image in cache) or by picking an image which is already saved in the gallery. I am able to click the image and also pick it up from the gallery, but I am not able to upload the image binary to Cloudinary.
I tried with sending binary data through $cordovaCamera
, $cordovaFile
, and also by passing URL but failed both ways. Is there something I am missing?
Here is what I configured for my camera:
vm.takePicture = function () {
var options = {
quality : 100,
destinationType : Camera.DestinationType.DATA_URL,
//destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
//saveToPhotoAlbum: true
};
vm.UploadPicture = function () {
vm.uploadinProgress = true;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = Image.jpeg;
options.chunkedMode = false;
options.trustAllHosts = true;
$cordovaFile.UploadFile("http://myserver.com/images", vm.imgSrc, options).then(function(result) {
console.log("Success");
},function error() {
console.log('Error: ' + error);
});
};
};