Skip to content

Instantly share code, notes, and snippets.

@singhmohancs
Created April 28, 2017 19:33
Show Gist options
  • Save singhmohancs/c0c8825922aa4be7fb67481eaf196004 to your computer and use it in GitHub Desktop.
Save singhmohancs/c0c8825922aa4be7fb67481eaf196004 to your computer and use it in GitHub Desktop.
Upload file in angularJs
$resource('/path/to/api/resource', null, {
upload: {
method: 'POST',
headers: { 'Content-Type': undefined },
transformRequest: function (data) {
var formData = new FormData();
formData.append("data", angular.toJson(data.model));
angular.forEach(data.files, function (fileData) {
formData.append(fileData.name, fileData.binary);
});
return formData;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment