Here is an example code of the Endpoint
//readoperation inside @Endpoint
@ReadOperation
public FileSystemResource getCompressedFile(@selector String path){
File directory = new File(path);
//Creating archive file with .tar.gz extension.
return new FileSystemResource(path+"filename.tar.gz");
}
I am able to download the file directly by calling the api from browser. Now I want to fetch this from codecentric spring-boot-admin view.
Here is my view js.
// Tried this call with other endpoint url's and it is working from axios calls.
// Except the following code which should download the file.
// This works when I use wiremock and download the file for testing purpose.
// But fails in real world scenario
async downloadLogs(){
try{
await this.instance.axios({
method: "get",
url:"/actuator/logs",
params: { 'path': '/working/path' },
responseType:'blob'
}).then((response)=>{
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'Logfile.tar.gz');
document.body.appendChild(link);
link.click();
}
);
}
catch(error){
console.log(error);
this.error = {
message: "Failed to download compressed file",
errorMessage: error.message
}
}
}
This call does not download the logs even though it returns 200 status.
I have tried various stuff mentioned in the following links
Also tried replicating a button like heapdump does in here: https://github.com/codecentric/spring-boot-admin/blob/875cc286a4be089aa5f39c8b54a99405beba2f92/spring-boot-admin-server-ui/src/main/frontend/views/instances/heapdump/index.vue#L26 .
Still I can't seem to get it working to download. I checked the response and it did not match the data I got in postman. the response data from SBA was like this.
<!DOCTYPE html><html><head><base href="https://springbootadmin.example.site.net/"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="format-detection" content="telephone=no,email=no"><meta name="theme-color" content="#42d3a5"><link rel="preload" href="extensions/ibus/css/ibus.40870333.css" as="style"><link rel="preload" href="extensions/ibus/js/ibus.749714cb.js" as="script"><link href="extensions/ibus/css/ibus.40870333.css" rel="stylesheet"><link rel="shortcut icon" href="assets/img/favicon.png" type="image/png"><title>Spring Boot Admin</title><link href="assets/css/chunk-common.d53d578b.css" rel="preload" as="style"><link href="assets/css/sba-core.ba8250f6.css" rel="preload" as="style"><link href="assets/js/chunk-common.995886c3.js" rel="preload" as="script"><link href="assets/js/chunk-vendors.ef23718c.js" rel="preload" as="script"><link href="assets/js/sba-core.cfd20c10.js" rel="preload" as="script"><link href="assets/css/chunk-common.d53d578b.css" rel="stylesheet"><link href="assets/css/sba-core.ba8250f6.css" rel="stylesheet"></head><body><div id="app"></div><script lang="javascript" src="sba-settings.js"></script><script lang="javascript" src="extensions/ibus/js/ibus.749714cb.js"></script><script src="assets/js/chunk-vendors.ef23718c.js"></script><script src="assets/js/chunk-common.995886c3.js"></script><script src="assets/js/sba-core.cfd20c10.js"></script></body></html>
Is there any way that the file can be downloaded in the given path from SBA View. Any method that takes the path and then returns file in path (.tar.gz filepath) ex: /tmp/logfile.tar.gz will also help.
Note : When call is made to the existing api directly from browser it already asks for option to save or open the file. I am calling the same api from axios get request. And i have no option to use href: I have already tried that.