0

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.

1

1 Answer 1

1

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>");
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

This is how I've ended up doing it but it just felt messy. I'm coming from a few months on AngularJS development and I was hoping for a more elegant solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.