O'Reilly logo

Mastering Backbone.js by Abiee Echamea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Uploading images from Backbone

To allow us to upload files from our Backbone application, we should create an input file to be able to show a Choose file dialog. This could be done in the ContactEditor sub-application by changing the ContactPreview class to add this functionality. So let's change the current template and add the input:

<div class="box thumbnail">
<div class="photo">
<% if (avatar && avatar.url) { %>
<imgsrc="<%= avatar.url %>" alt="Contact photo" />
<% } else { %>
<imgsrc="http://placehold.it/250x250" alt="Contact photo" />
<% } %>
<input id="avatar" name="avatar" type="file" 
style="display: none" />
</div>
<!-- ... -->
</div>

Note that we have created a hidden input file field; we don't want to show the input field, but we want ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required