I have a contentUrl when user clicks on that,file should be downloaded. If I try to browse the contentUrl in the browser it asks for Userid and password.I believe this is Basic Authentication.I dont want user to enter UserId and Password so I am passing it Authorization(Please see below code). Url looks some thing like this: http://XXX.XXX.XX.XXX:8080/flowable-rest/service/runtime/tasks/90875/attachments/90555/content
let username : string = 'admin';
let pwd : string = 'test';
let headers = new Headers();
headers.set('Accept', 'text/json');
headers.append('Content-Type', 'application/json');
headers.set('Access-Control-Allow-Origin', '*');
headers.set('Access-Control-Allow-Methods','POST, GET, OPTIONS, PUT, DELETE');
headers.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
headers.append("Authorization", "Basic " + btoa(username + ":" + pwd));
return this.http.get(url, { headers: headers })
.pipe(map(r => {
console.log(r);
})).pipe(catchError(this.handleError));
I am not 100% sure whether this approach is fine for my requirement.
I tried contentUrl in the PostMan.In PostMan down right corner 'Download' button appeared and asked me to download.Below is the message it says
This response could not be previewed. Download the response to open it with an appropriate application.
If I click on Download my attachment is getting downloaded.
Pro-grammatically is http.get equivalent to Download? If not how should I code it? Basically my requirement is if I click on the link attachment should be downloaded.