-1

I am working on codeigniter project and when I enable CSRF protection in config file and added csrf token hidden field in all forms site working fine but due to this I am facing one problem i.e. "The action you have requested is not allowed" while uploading images using dropzone.

How to pass the csrf token in dropzone js?

When I upload image in dropzone box it gives error:

The action you have requested is not allowed.

<div class="dropzone clsbox" id="mydropzone">
</div>  

$("div#mydropzone").dropzone({                      
  url: "/riftraff/insert_product_phase_final",
  headers: {
    'X-CSRFToken': $('meta[name="_token"]').attr('content')
  }                                                             
}); 
Styx
  • 9,863
  • 8
  • 43
  • 53
preeti
  • 47
  • 5

1 Answers1

4
var myDropzone = new Dropzone("div#mydropzone", {
  url: "/riftraff/insert_product_phase_final"
}); 

myDropzone.on('sending', function(file, xhr, formData) {
  formData.append('<token_name>', '<token_value>');
});
Styx
  • 9,863
  • 8
  • 43
  • 53
preeti
  • 47
  • 5