Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

Cannot $http POST file to Laravel

$
0
0

@VolvoOlympian wrote:

I am trying to POST a file along with other form data to my Laravel API, but the file was not received by the API:

 $http({
    method: 'POST',
    url: '/upload-file',
    headers: {
        'Content-Type': 'multipart/form-data'
    },
    data: {
        email: Utils.getUserInfo().email,
        token: Utils.getUserInfo().token,
        upload: $scope.file
    },
    transformRequest: function (data, headersGetter) {
        var formData = new FormData();
        angular.forEach(data, function (value, key) {
            formData.append(key, value);
        });

        var headers = headersGetter();
        delete headers['Content-Type'];

        return formData;
    }
})
.success(function (data) {

})
.error(function (data, status) {

});

And I have this directive:

app.directive('file', function () {
return {
scope: {
file: '='
},
link: function (scope, el, attrs) {
el.bind('change', function (event) {
var file = event.target.files[0];
scope.file = file ? file : undefined;
scope.$apply();
});
}
};
});

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>