Using Dropzone.js to upload after new user creation, send headers

前端 未结 2 1814
闹比i
闹比i 2021-02-14 07:47

I\'m using a great plugin - dropzone.js (dropzonejs.com) to make my site a little more fancy when registering a new user.

Basically, the user fills out a form, drops a c

相关标签:
2条回答
  • 2021-02-14 08:16

    If you use the latest Dropzone version, the parameter enqueueForUpload has been removed, in favour of autoProcessQueue which makes the whole queuing easier.

    So, just call myDropzone.processQueue() as soon as you want all files to be uploaded.

    To add additional parameters to the XHR you can simply register to the sending event, which gets the xhr object as second and formData as third parameter, and add the data yourself. Something like this:

    myDropzone.on("sending", function(file, xhr, formData) {
      // add headers with xhr.setRequestHeader() or
      // form data with formData.append(name, value);
    });
    
    0 讨论(0)
  • 2021-02-14 08:22

    I used enyo answer, but i used many dropzones with data-id attribute in my page so I used:

    $('div.dropzone').dropzone({
        url: 'img.php'
    });
    var sendingHandler = function(file, xhr, formData) {
        formData.append('id', $(this.element).data('id'));
    };
    $('div.dropzone').each(function() {
        Dropzone.forElement(this).on('sending', sendingHandler);
    });
    
    0 讨论(0)
提交回复
热议问题