1

I'm trying to send the file as response in node API.

In my front end I'm getting this error : Unexpected token H in JSON at position 0 at JSON.parse

In that error I can see the filecontent.

API Code

        res.download(path,'file.txt',(error) => {
            if(error) {
                error.status = 500
                res.json({
                        status  : error.status,
                        message : error.message,
                     })
            }

        })

Front-End

this.apiservice.downloadattachments('file.txt').subscribe(response => console.log(response))

apiservice


downloadattachments(filePath) : Observable<any> {
  let httpParams = new HttpParams()
  .set('FilePath',filePath)
  return this.http.get<any>(this.baseURL+"/download/attachments",{params : httpParams})
}

Shivaay
  • 51
  • 1
  • 10

0 Answers0