在每个文件上传中使用dropzone.js发送自定义数据 [英] Send custom data with dropzone.js on each File Upload
本文介绍了在每个文件上传中使用dropzone.js发送自定义数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Code Igniter项目中使用dropzone.
I am using dropzone in my Code Igniter Project.
每次拖动文件时,dropzone都会创建一个ajax请求,我的文件也将存储在服务器上.但是现在,我的要求是我想在文件旁边发送其他数据( DYNAMIC ). 通过使用参数,只能发送静态数据,但是我要发送的数据每次都会更改.
With every drag of a file, dropzone creates an ajax request and my files is getting stored on the server too. But now, my requirement is that I want to send additional data (DYNAMIC) alongside the file. With the use of params, Only static datas can be sent, but the data I want to send will be changing everytime.
这是我的代码的样子:
<script>
Dropzone.autoDiscover = false;
Dropzone.options.attachment = {
init: function(){
this.on('removedfile',function(file){
// console.log('akjsdhaksj');
var fileName = file.name;
$.ajax({
type: 'POST',
url: "<?php echo BASE_URL.'index.php/admin/mail_actions/deleteFile' ?>",
data: "id="+fileName,
dataType: 'html'
});
});
},
// params: {
// customerFolder: $('#toValue').substr(0, toValue.indexOf('@')),
// },
dictDefaultMessage:"Click / Drop here to upload files",
addRemoveLinks: true,
dictRemoveFile:"Remove",
maxFiles:3,
maxFilesize:8,
}
$(function(){
var uploadFilePath = "<?php echo BASE_URL.'index.php/admin/mail_actions/uploadFile' ?>";
var myDropzone = new Dropzone("div#attachment", { url: uploadFilePath});
});
</script>
我能实现吗?
推荐答案
我明白了. 这就是我必须使用的
I got it. This is what I had to use
myDropzone.on('sending', function(file, xhr, formData){
formData.append('userName', 'bob');
});
这篇关于在每个文件上传中使用dropzone.js发送自定义数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文