Skip to content

Instantly share code, notes, and snippets.

@HereChen
Created July 4, 2017 12:02
Show Gist options
  • Save HereChen/89bba9437b3fd5795e7edecf40a92b8a to your computer and use it in GitHub Desktop.
Save HereChen/89bba9437b3fd5795e7edecf40a92b8a to your computer and use it in GitHub Desktop.
angularjs-file-upload
// https://stackoverflow.com/questions/16483873/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