lundi 27 mars 2017

POST input files via AngularJS to back-end

I have a store() in my AngularJS Controller, I don't understand why I can not POST my files into my back-end controller in PHP Laravel.

This is what I have

$scope.store = function() {
    $scope.model = {
      name: $scope.name,
      type: $scope.type
    };

    $http({
        method: 'POST',
        url: '/image/store',
        headers: { 'Content-Type': undefined },
        transformRequest: function (data) {
            console.log("data coming into the transform is ", data);
            var formData = new FormData();
            formData.append("model", angular.toJson(data.model));
            for (var i = 0; i < data.files; i++) {
                formData.append("file" + i, data.files[i]);
            }
            console.log($scope.files); <------------ It works perfectly fine here. 
            return formData;
        },

        data: { model: $scope.model, files: $scope.files }

    })


    .then(function successCallback(response) {
        console.log("%cSuccess!", "color: green;");
        console.log(response);
        $scope.refresh();
        $scope.showModal = false;
        }, function errorCallback(response) {
        console.log("%cError", "color: red;");
        console.log(response);
    });
};


console.log($scope.files);

return

enter image description here


In my back end controller, I only some of my data which is my model.

array:1 [
  "model" => "{"type":"wedding"}"
]

What did I do wrong ?

Can someone please shed some light on this ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nsWjWs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire