2

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
  • 24,540
  • 10
  • 85
  • 154
Manu Mohan Thekkedath
  • 1,518
  • 1
  • 19
  • 31

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
  • 31,489
  • 10
  • 78
  • 113