I have a react app where I have to download file on press of a button,Here's how my java backend is returning the file in get request:
if (Files.exists(filePath)) {
response.setContentType(Files.probeContentType(filePath));
response.addHeader("Content-Disposition", "attachment; filename=" + file.getName());
Files.copy(filePath, response.getOutputStream());
response.getOutputStream().flush();
}
How do I read it in the react frontend and download it on button press?