[Django]-Backbone.js link file to model

0👍

Basically the Web browser decides when a file is uploaded, not the server. The server may receive the file in request.FILES. You can then handle the model.save() after the browser has submitted the file. For more information you should see Django’s very good documentation site: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs

The model in backbone.js provides a means to use a model to process the data. BUt Django has its own facilities for receiving files as noted above.

0👍

The problem is that you can’t use file upload with AJAX directly.
The common workaround is to submit a form to a hidden iframe.

You can use jQuery Form plugin. It provides ajaxSubmit method, it works like jQuery.ajax call but uses hidden iframe so it can upload files.

Also you need to override Backbone.sync or override sync on a per-model basis and replace $.ajax call with $(someForm).ajaxSubmit call

On server you should return JSON string with id parameter and file parameter containing file url

👤Igor

Leave a comment