I'm trying to upload a picture from my app to the server using ionic
$cordovaFile
plugin, Following is my code
$cordovaCamera.getPicture(options).then(function(imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
options = {
fileKey: "avatar",
fileName: "image.png",
chunkedMode: false,
mimeType: "image/jpeg"
}
$cordovaFile.uploadFile('http://localhost:3001/images/',$scope.imgURI, options)
.then(function(result){
console.log("Code = ok");
}, function(error){
console.log("Code = " + error);
}, function(progress){
})
}, function(err) {
//An error occured. Show a message to the user
});
and here is how I added it in the page
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
The problem is when I run the project, it prompts me the camera and when I get the picture I'm getting the following error in my console
[phonegap] [console.error] Error: Can't find variable: FileTransfer
[phonegap] uploadFile@http://10.1.1.4:3000/js/ng-cordova.min.js:7:24346
[phonegap] http://10.1.1.4:3000/js/controllers/picture_ctrl.js:32:36
...
Im using phonegap developer app
as the simulator
What would be the reason.
Thanks in advance
You'll need to install the cordova file-transfer plugin via:
cordova plugin add org.apache.cordova.file-transfer