How to send params value calculated at runtime in dropzone.js?

Member

by lew , in category: Javascript , 14 days ago

How to send params value calculated at runtime in dropzone.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by aniya.jaskolski , 13 days ago

@lew 

To send params value calculated at runtime in Dropzone.js, you can use the sending event callback function provided by Dropzone.js.


Here's an example of how you can send params value calculated at runtime:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var myDropzone = new Dropzone("#my-dropzone", {
    url: "/upload",
    paramName: "file",
    autoProcessQueue: true,
    sending: function(file, xhr, formData) {
        // Calculate the params value at runtime here
        var paramsValue = "myParamsValue";

        // Add the params value to the formData
        formData.append("myParamsKey", paramsValue);
    }
});


In this example, we created a new Dropzone instance and added a sending event callback function. Inside this function, we calculate the params value at runtime and append it to the formData parameter. This way, the calculated params value will be sent along with the file when it is uploaded.


You can customize the params value calculation logic inside the sending event callback function as needed.