Sam Marland
Sam Marland

Reputation: 572

Backbone JS Single Page Application file upload?

I'm looking for some design patterns or best practices around uploading files from a form to a REST end point.

The REST endpoint is already working and I can POST files to it. Any thoughts would really be appreciated.

Upvotes: 0

Views: 452

Answers (1)

Dethariel
Dethariel

Reputation: 3614

Is that what you're looking for?

var FileUploadView = Backbone.View.extend({
    events: {
        "click #submit": function() {
            $.ajax({
                url: '%YOUR_URL%',
                type: 'POST',
                data: new FormData(this.$('#form')[0]),
            });
        }
    },
    render: function() {
        this.$el.html("<form id='form'><input type='file' /><input id='submit' value='Upload File' type='button' /></form>");
    }
};

Upvotes: 1

Related Questions