Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created October 13, 2014 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abuiles/5878f905c51714775b36 to your computer and use it in GitHub Desktop.
Save abuiles/5878f905c51714775b36 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import { request } from 'ic-ajax';
export default Ember.Component.extend({
actions: {
upload: function() {
var _this = this;
var formData = new FormData();
formData.append("file", this.$('input')[0].files[0]);
var url = this.get('url');
request('/your-api-end-point-which-accepts-csv', {
type: 'POST',
data: formData,
dataType: 'json',
processData: false,
contentType: false,
xhr: function() {
var xhr;
xhr = Ember.$.ajaxSettings.xhr();
xhr.upload.onprogress = function(evt) {
return _this.set('uploadProgress', evt.loaded / evt.total * 100);
};
return xhr;
}
}).then(function() {
console.log('manage success here');
}, function() {
console.log('manage failure');
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment