1

I want to make non-json request to server using angular 6 HttpClient (@angular/common/http) to get Octet-stream . Below is my code.

getFile(file: any) {
    let headers: new HttpHeaders({
        'Content-Type':  'application/octet-stream',
        'Accept':'application/octet-stream',
        'Authorization': 'Bearer ' + data.token
    })

    return this.http.get<any>(this.baseUrl + '/getfile/'+file, headers);
}

But this gives me JSON parse error.

"HttpErrorResponse", message: "Http failure during parsing for..... ERROR {…} ​ error: {…} ​​ error: SyntaxError: "JSON.parse: unexpected character at line 1 column 1 of the JSON data"

Whats the way to read it as non-json?

hlovdal
  • 23,353
  • 10
  • 78
  • 148
Manu Mohan Thekkedath
  • 1,378
  • 17
  • 30

1 Answers1

6

Try this:

let headers = new HttpHeaders({
    'Authorization': 'Bearer ' + data.token
    });
return this.http.get<any>(this.baseUrl + '/getfile/'+file, {headers:headers, responseType: 'blob'});
David
  • 28,746
  • 10
  • 68
  • 95