Hello everybody I'm new in Laravel and reactjs and I have a question, I try to download file from the server to the browser. My request is ok but the file that I wanted is not readable (if I right click on my browser Network->Preview I find symbols and caracters not readable) also the file isn't downloaded. I used visual studio code for coding in windows.
DownloadController:
public function download()
{
$file = public_path()."/file.pdf";
return response()->download($file);
}
routes/api.php:
Route::get('download','Api\DownloadController@download');
In the file Js:
import React, { Component } from 'react';
import axios from 'axios';
export default class download extends Component{
constructor () {
super();
}
componentDidMount() {
axios.get(`http://127.0.0.1:8000/api/download`)
.then((response) => {
console.log('hello');
});
}
render() {
return (
<div>
<button onClick={this.componentDidMount.bind(this)} className="btn btn-primary">Download</button>
</div>
);
}
}