Skip to content

Instantly share code, notes, and snippets.

@jreading
Created December 13, 2013 22:54
Show Gist options
  • Save jreading/7952848 to your computer and use it in GitHub Desktop.
Save jreading/7952848 to your computer and use it in GitHub Desktop.
File uploading in angular
<input type="file" onchange="angular.element(this).scope().myController.uploadFile(this.files[0]); angular.element(this).scope().$digest();">
var uploadFile = function(file) {
var formData = new FormData();
formData.append('file', file);
$http({
method: 'POST',
url: 'url-to-accept-file',
data: formData,
headers: { 'Content-Type': undefined },
transformRequest: function(data) { return data; }
})
.success(handleSuccess)
.error(showError);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment