My goal is to download a file by sending necessary parameters through an ajax request.
In the process, I saved the output file in the public/exports
directory and attempted to redirect to that file path in the success callback.
public function downloadResults() {
/* get filter control inputs */
$inputParams = $this->request->input();
.
.
.
try {
$exportArr = $this->product->downloadResults($filterArr); <-- this will store the file to public directory.
} catch (\Exception $e) {
$jsonArr['success'] = false;
$jsonArr['message'] = $e->getMessage();
echo json_encode($jsonArr);
}
$jsonArr['success'] = true;
$jsonArr['filename'] = $exportArr['file'];
echo json_encode($jsonArr);
}
Upon receiving the response,
$.ajax({
data: filter_rules,
url: "{{ @url("/dmf/download-results") }}",
type: 'POST',
dataType: 'json',
success: function(resp) {
$("#overlay").hide();
window.location.href = "{{ asset('public/exports/') }}" + '/' + resp.filename;
},
});
}
This leads to a redirection to a non-existent route
http://localhost:8000/public/exports/result_set_download_1589388303.xls
.
What steps should be taken to access the file now?