In my app users can download a file as a stream from the backend which is a spring boot application, here's the backend code:
@RequestMapping(value = "/download", method = RequestMethod.GET)
public StreamingResponseBody download() throws IOException {
final InputStream fecFile = new FileInputStream(new File("C:\\file.zip"));;
return (os) - > {
readAndWrite(fecFile, os);
};
}
private void readAndWrite(final InputStream is, OutputStream os) throws IOException {
byte[] data = new byte[2048];
int read = 0;
while ((read = is.read(data)) >= 0) {
os.write(data, 0, read);
}
os.flush();
}
Inside angular I'm using the following to download the file:
window.location.href = "http://localhost:8080/download"
Which work's fine, but I added a access token based authentication, and I cannot add a token to window.location.href, is there a way to do this in angular, I tried using the HttpModule but it's not downloading the file ( it doesn't show any response or error, even though my controller was called ), so is there a way to achive this maybe using jquery or another libreary ?