-2

I'm calling an Angular component which calls an api service I created to call a nodejs back-end. The back-end download a zip file, using res.download. I believe that the response is not correctly handled, because when I call the back-end directly from the url (localhost:3000/api/download/file), it works perfectly. Here's the code below :

1) Angular component

downloadZipFile(index) {
    this._apiService.downloadZip(index).subscribe(data => {
    });
  }

2) Angular apiService

downloadZip(index) {
    return this._http.get('http://localhost:3000' + appConfig.__apiUrl + 'download/' + index);
  }

3) NodeJS API

router.get('/download/:index', (req, res) => {
  res.download(path.join(__dirname, 'downloads/' + req.params.index + '.zip'));
});
  • Resolved : Tried this solution and it works perfectly https://stackoverflow.com/questions/50907542/download-a-file-from-asset-folder-when-clicking-on-a-button – Nicolas Mazzoleni Mar 04 '19 at 13:36

1 Answers1

0

You are attaching multiple time API url in your angular service HTTP request. Please remove one of them. and check again.

downloadZip(index) {
    return this._http.get('http://localhost:3000/download/' + index);
  }

Add above code in your service.

shubham chhapre
  • 296
  • 1
  • 14