I have a button in my reactjs application which when clicked should download a file. I need to send a token with the request to let user download the file. How can I send a token with it? Had it been a ajax, I would have sent the token in header.
This is my code
<div className="btn btn-default obj-export-btn" onClick={this.exportObjectReport.bind(this)}><span className="fa fa-download"></span></div>
exportObjectReport(){
window.location = url + "get_labels/";
}
exportObjectReport is to download the file.
I tried using ajax. But file doesn't get download then. Ajax gets success but no download.
exportObjectReport(){
// window.location = this.props.video_file_selected.file_url + "get_labels/";
var that = this;
var existing_face_array = [];
var settings = {
"async": true,
"crossDomain": true,
"url": url + "get_labels/",
"method": "GET",
"headers": {
Authorization: "Token " + that.props.token_Reducer.token
},
success: function (response, textStatus, jQxhr) {
console.log('export success')
},
}
$.ajax(settings).done((response) => {
});
}