Created
December 8, 2015 12:35
-
-
Save felipekm/e07db14929f33d6e072c to your computer and use it in GitHub Desktop.
Angularjs $http post file and form data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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) { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment