Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active July 25, 2018 14:28
Show Gist options
  • Save wholypantalones/74bc0a46720389d55e4a613beceb0313 to your computer and use it in GitHub Desktop.
Save wholypantalones/74bc0a46720389d55e4a613beceb0313 to your computer and use it in GitHub Desktop.
Angular 1.x.x multipart form data post
// angular.identity: see https://softwareengineering.stackexchange.com/a/283119
// Content-Type: undefined: see https://www.uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs/
// new File([data], file): must be a blob or array see https://developer.mozilla.org/en-US/docs/Web/API/Blob
var fd = new FormData(),
file = new File([data], objectName);
fd.append('file', file);
return $http.put('path/to/url', fd, {
transformRequest: angular.identity,
transformResponse: function(data) {
return {
content: data
};
},
headers: {
'Content-Type': undefined
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment