jeanphix / django-resumable

django backend for resumable.js xhr uploads.
61 stars 21 forks source link

Hi....is there any way to send custom query values for the resumable POST request #7

Open pconesa opened 8 years ago

pconesa commented 8 years ago

I need to send in the POST (chunks) request 2 parameters.

If I initialize DjangoResumable like this:

document.addEventListener("DOMContentLoaded", function () {
   "use strict";
   var dj;
   if (new Resumable().support) {

      var resumableOptions =  {
         query: {
            'p': 'betagal1'
         }
      };

      var djangoResummableOpts = {
         resumableOptions: resumableOptions
      }

      dj = new DjangoResumable(djangoResummableOpts);
   }
});

the resumableOptions are overwritten during the initResumable:


opts = {
   target: el.getAttribute(this.options.urlAttribute),
      query: {
         'csrfmiddlewaretoken': this.csrfToken
      }
   };

opts = this.extend(this.options.resumableOptions, opts);

In the extend method, the whole query method (my customized options) are replaced by the 'default' ones ( the one with the 'csrfmiddlewaretoken')

Something that will fix it will be to recursively call extend if an object is found: and present in target:


            // Customize extend function to avoid query params to be overwritten
                DjangoResumable.prototype.extend = function (target, source) {
                    "use strict";
                    var property;
                    for (property in source) {
                        if (source.hasOwnProperty(property)) {
                            if (target[property] !== undefined && typeof source[property] === 'object') {
                                target[property] = this.extend(target[property], source[property]);
                            } else {
                                target[property] = source[property];
                            }

                        }
                    }
                    return target;
                };