I am trying to use this, krajee bootstrap-fileinput library with Django python framework. I need to pass csrf_token
via headers to submit the file via ajax to the server. Where should I put csrf_token? In general, I used to pass as a header in ajax method in jquery. Now I don't understand where should I have to include csrf_token
. Do I have to put in fileinput
?
Asked
Active
Viewed 917 times
2

Naroju
- 2,637
- 4
- 25
- 44
-
Did you fix this? – Edwin Krause Apr 12 '18 at 10:38
1 Answers
2
Although this is a very old question, here is the answer. I had the same issue with using the bootstrap-file-upload plugin and I solved it by adding the crsf token to as uploadExtraData
Laravel adds the token into a globally available variable
<script>
window.Laravel = {"csrfToken":"PQwQZyeHaARm0gf52qzvIdl3T203FhmPT90K2bLX"};
</script>
You can then make use of it, when assigning the bootstrap-file-upload widget
$(document).ready(function(){
$("#file_uplooad").fileinput({
uploadUrl:'/ajax/fileupload',
uploadExtraData:{
_token:window.Laravel.csrfToken // we pass it here to the server
}
});
});
Although this is a very late answer, I still hope that someone will benefit from it. Have fun!

Edwin Krause
- 1,766
- 1
- 16
- 33