Send custom data with dropzone.js on each File Upload

前端 未结 4 1391
孤独总比滥情好
孤独总比滥情好 2020-12-23 19:38

I am using dropzone in my Code Igniter Project.

With every drag of a file, dropzone creates an ajax request and my files is getting stored on the server too. But now

4条回答
  •  死守一世寂寞
    2020-12-23 20:12

    In case you have a nested payload object - e.g. to add a name to your file and your api only accepts something like this

    {
        someParameter: {
            image: ,
            name: 'Bob'
        }
    }
    

    your dropzone setup would look like this

    var myDropzone     = new Dropzone("div#attachment", { 
        url: uploadFilePath,
        paramName: 'someParameter[image]'
    });
    
    myDropzone.on('sending', function(file, xhr, formData){
        formData.append('someParameter[image]', file);
        formData.append('someParameter[userName]', 'bob');
    });
    

    I only added this as there was no example for nested parameters documented since now.

提交回复
热议问题