Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Downloadable link from rest API response in angular is asking for authentication

There is a sprint boot API, which is configured with authentication, on accessing it, the response will be a Downloadable link.

enter image description here

I tried integrated the same in angular as follows : Basically, using a service file to invoke the rest API, on successful invocation, i am reading the url from the response and , using an anchor tag to append it to document body and click it programmatically ,

constructor(private api: ApiService)
this.api.getLogs(param).subscribe(result =>{
      
      if (result.status == 200) {
          var file_path = result['url'];
          let a = <HTMLInputElement>document.createElement('A');
          $(a).attr("href", result['url']);
          $(a).attr("download", file_path.substr(file_path.lastIndexOf('/') + 1));
          document.body.appendChild(a);
          a.click();
          document.body.removeChild(a);
          
      } else {
        
        console.log('failed');
      }
    });

And in the service file, I used httpHeaders to include the username and password while invoking the rest API.

public getLogs(data):Observable<any>{
    const url = 'http://<localhost>:<port>:</path>'
    return this.http.get(url, {
      headers: new HttpHeaders({ 'Authorization': 'Basic ' + btoa('test:test') }), 
      observe: 'response'});
  }

But when this is executed in browser, the app redirects to the url shared by API response and it asks for the authentication. However once i give the credentials, all the following invocations are not asking for this. What is that is missing here, or is there anything i was implementing it in wrong way , let me know.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!