Last active
August 29, 2015 14:20
-
-
Save cowboyd/1b634f5e4a2e738e9874 to your computer and use it in GitHub Desktop.
This file contains 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
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