@andrepiper wrote:
Hello Ionic community, whenever i include $cordovaFileTransfer in my project the camera Launcher is not executed..thus no camera pops up, but when i remove $cordovaFileTransfer from the project the camera comes up, so my question is this a new error/bug because i cant find anyone that has encountered this problem. Any help would be greatly appreciated
MY CODE
.controller('KycStep3Ctrl', function($scope, $state,$stateParams,$ionicPopup, $cordovaCamera,LeadsRoute,$timeout, $cordovaFileTransfer) {
console.log('step-3-loaded');
$scope.lead = JSON.parse($stateParams.lead);//-----------
$scope.images = [];
$scope.addImage = function() { document.addEventListener("deviceready", function () { // 2 var options = { destinationType : Camera.DestinationType.FILE_URI, sourceType : Camera.PictureSourceType.CAMERA, // Camera.PictureSourceType.PHOTOLIBRARY allowEdit : false, encodingType: Camera.EncodingType.JPEG, popoverOptions: CameraPopoverOptions, }; // 3 $cordovaCamera.getPicture(options).then(function(imageData) { console.log('snap-trigger'); // 4 onImageSuccess(imageData); function onImageSuccess(fileURI) { createFileEntry(fileURI); //---- console.log('starting upload'); var url = LeadsRoute.getUploadRoute(); //File for Upload var targetPath = fileURI; // File name only var filename = targetPath.split("/").pop(); var options = { fileKey: "file", fileName: filename, chunkedMode: false, mimeType: "image/jpg", params : {lead:lead, 'fileName':filename} // directory represents remote directory, fileName represents final remote file name }; $cordovaFileTransfer.upload(url, targetPath, options).then(function (result) { console.log("SUCCESS: " + JSON.stringify(result.response)); }, function (err) { console.log("ERROR: " + JSON.stringify(err)); }, function (progress) { // PROGRESS HANDLING GOES HERE }); } function createFileEntry(fileURI) { window.resolveLocalFileSystemURL(fileURI, copyFile, fail); } // 5 function copyFile(fileEntry) { var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1); var newName = makeid() + name; window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) { fileEntry.copyTo( fileSystem2, newName, onCopySuccess, fail ); }, fail); } // 6 function onCopySuccess(entry) { $scope.$apply(function () { $scope.images.push(entry.nativeURL); }); } function fail(error) { console.log("fail: " + error.code); } function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i=0; i < 5; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } }, function(err) { console.log(err); }); }); }
$scope.urlForImage = function(imageName) {
var name = imageName.substr(imageName.lastIndexOf('/') + 1);
var trueOrigin = cordova.file.dataDirectory + name;
return trueOrigin;
}})
Some code taken from here
Posts: 2
Participants: 1