SingleClick Upload Button for AngularJS
A custom directive that gives you a button when clicked prompt for the file and uses XHR2 to post the file to the server using the action attribute as the endpoint.
When complete, the directive fires the function set to the complete attribute.
<upload-button
action="api/file"
complete="uploaded($data, $status)">
Upload File
</upload-button>
The server posts the file under the field uploadFile.
app.post('/api/file', function(req,res) {
console.log(req.files.uploadFile);
res.send();
});
bower install angular-upload-button
<script src="/bower_components/angular-uploadBtn/upload-button-btn.js"></script>
angular.module('App', ['upload.button']);
File issues on github
MIT
Still lots to do here, we can add progress tracking and other attributes to make the button control extremely robust. Suggestion and Pull Requests are welcome
If you need compatibility for IE 8 and below, you may want
to checkout ng-upload
.
http://twilson63.github.io/ngUpload/