-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')
  }                                                             
}); 
5
  • Are you sure that dropzone accepts the "headers" parameter? Commented Oct 6, 2017 at 7:18
  • No, I am not sure then how to send the csrf token in dropzone request? Commented Oct 6, 2017 at 7:22
  • @preeti then look at the Dropzone documentation??? Commented Oct 6, 2017 at 7:23
  • it seems you can dropzonejs.com/#config-headers Commented Oct 6, 2017 at 7:23
  • have a look at stackoverflow.com/questions/29073878/…. you can send csrf token in form data also. Commented Oct 6, 2017 at 11:20

1 Answer 1

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>');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.