Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Last active August 29, 2015 14:20
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 cowboyd/1b634f5e4a2e738e9874 to your computer and use it in GitHub Desktop.
Save cowboyd/1b634f5e4a2e738e9874 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import XHR from 'ember-xhr';
/**
* On the rails server, this creates an active record that stores the
* filename and generates the pre-signed url, the return format is
* something like:
*
* {
* "upload": {
* "filename": "bob.tgz",
* "url": 'http://thepresigned-url'
* }
* }
*/
export default Ember.Route.extend({
actions: {
/**
* `file` is a File object read from input.file
* @param {File} file
*/
performUpload(file) {
$.post('/uploads', {
filename: file.name
}).then(Ember.run.bind(this,function(data) {
var xhr = XHR.create();
xhr.open(data.upload.url);
xhr.send(file);
this.set('controller.xhr', xhr);
}));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment