Last active
July 25, 2018 14:28
-
-
Save wholypantalones/74bc0a46720389d55e4a613beceb0313 to your computer and use it in GitHub Desktop.
Angular 1.x.x multipart form data post
This file contains hidden or 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
// 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