Camera API, send fileURI to distant server

Hello everyone ! I’m almost done with my ionic app but i still have a few problems with the cordova camera API.

when the picture is taken, the console.log(imageURI) clearly displays the path to the local storage’s picture.

However, i want to send this picture to a distant server, as a $file input

my controller looks like this :

$scope.getPhoto = function() {

    PhotoService.getPicture().then(function(imageURI) {
    
        $scope.image = imageURI;
    }, function(err) {
        console.err(err);
    });
};

and then, when i try to upload it with other values (title, description, etc…) I use this function :

$scope.create = function (produit) {

    var file = "script.php";
    produit.id_user = $scope.id_user;
    RequestService.fileTransfer(file, $scope.image,values).then(function () { //this part sends to the file script the 2 following attributes, the imageURI and the attributes (title, description, etc...)

        $state.go('app.otherView', {}, {location: 'replace'}); //redirect when sent
        $ionicHistory.nextViewOptions({
            disableBack: true
        });
    }, function () {
        console.log("upload failed");
    });
}; 

my problem is, I need to send the $scope.imageURI in a way that the server receives a $file input, but i don’t know how, can someone help ?

Thanks in advance to whoever will answer ! :smiley:

No ideas ? Anyone ? :frowning:

Hi, maybe this helps:


http://www.clearlyinnovative.com/ionic-framework-camera-image-uploads-and-base64-strings/1

I will try this way of doing it, i’ll keep you updated !