Skip to content

Instantly share code, notes, and snippets.

@sidthesloth92
Created April 1, 2016 13:36
Show Gist options
  • Save sidthesloth92/d12d4e4c4b65ef9b0619adff9f4763db to your computer and use it in GitHub Desktop.
Save sidthesloth92/d12d4e4c4b65ef9b0619adff9f4763db to your computer and use it in GitHub Desktop.
yourModule.controller('FileController', function($scope, $cordovaCamera, $cordovaFile) {
$scope.fileName = "";
$scope.uploadPicture = function() {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 1024,
targetHeight: 768,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(sourcePath) {
var sourceDirectory = sourcePath.substring(0, sourcePath.lastIndexOf('/') + 1);
var sourceFileName = sourcePath.substring(sourcePath.lastIndexOf('/') + 1, sourcePath.length);
console.log("Copying from : " + sourceDirectory + sourceFileName);
console.log("Copying to : " + cordova.file.dataDirectory + sourceFileName);
$cordovaFile.copyFile(sourceDirectory, sourceFileName, cordova.file.dataDirectory, sourceFileName).then(function(success) {
$scope.fileName = cordova.file.dataDirectory + sourceFileName;
}, function(error) {
console.dir(error);
});
}, function(err) {
console.log(err);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment