Hi,
I’m trying to upload a photo since 4 days and it’s driving me crazy
Here’s my controller :
app.controller('AddPhotoCtrl', function($scope, $rootScope, $http, $state, $cordovaCamera, $cordovaFileTransfer) {
document.addEventListener("deviceready", function(){
$scope.takePic = function(){
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 600,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(
function(imageData) {
$scope.picData = imageData;
alert(imageData);
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var fileURL = imageData;
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURL, encodeURI($rootScope.api + 'photo-upload'), win, fail, options);
},
function(err){
alert('Error');
}
);
};
}, false);
});
Server side I just return a json with $_FILES["name"]
. (to know if it’s working)
So when I press on takePic() I can take a picture, edit it but when I press on save I’ve a FileTransferError.CONNECTION_ERR
What I’m doing wrong ?