Hello,
I want to upload a file from the mobile app to my server. The file browsing with cordova camera works perfect, but the I have problems in the upload part. If I use it like this I can’t even open the page with this method in it. If I delete $cordovaFileTransfer
on the first line in my function, I can open the page with this function but of course there is $cordovaFileTransfer
missing and it doesn’t work. My code does look like this:
function ($scope, $stateParams, $http, $cordovaCamera, $cordovaFileTransfer) {
$scope.uploadPhoto = function(){
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
//console.log(imageData);
//console.log(options);
var image = document.getElementById('tempImage');
image.src = imageData;
var server = "http://myserver.ch/upload.php",
filePath = imageData;
var date = new Date();
var options = {
fileKey: "file",
fileName: imageData.substr(imageData.lastIndexOf('/') + 1),
chunkedMode: false,
mimeType: "image/jpg"
};
$cordovaFileTransfer.upload(server, filePath, options).then(function(result) {
alert("SUCCESS: " + JSON.stringify(result.response));
alert('Result_' + result.response[0] + '_ending');
alert("success");
alert(JSON.stringify(result.response));
}, function(err) {
console.log("ERROR: " + JSON.stringify(err));
alert(JSON.stringify(err));
}, function (progress) {
// constant progress updates
});
}, function(err) {
alert(err);
});
}
}
Thanks in advance.