@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