Skip to content

Instantly share code, notes, and snippets.

@felipekm
Created December 8, 2015 12:35
Show Gist options
  • Save felipekm/e07db14929f33d6e072c to your computer and use it in GitHub Desktop.
Save felipekm/e07db14929f33d6e072c to your computer and use it in GitHub Desktop.
Angularjs $http post file and form data
$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