Manu Mohan
Manu Mohan

Reputation: 1814

Angular 6 Unable to read Octet-stream in HttpClient Error message: "Http failure during parsing for..."

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?

Upvotes: 2

Views: 12288

Answers (1)

David
David

Reputation: 34455

Try this:

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

Upvotes: 7

Related Questions