Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 5 HTTP failure during parsing for image

I want to get image from Express server with Angular using its filename:

Request from Angular service

And I want to send the file back to the client:

Sending file from Express server

When I log the response from the server I get the following error:

Error message from response

I am nearly sure that I am missing any options either in my request or in my response, but I am not sure what.

Any help would be highly appreciated.

like image 711
Deyan Peychev Avatar asked Jul 18 '18 19:07

Deyan Peychev


Video Answer


1 Answers

HttpClient applay 'json()' method to the respond so if your respond is non-JSON data you will get this kind of error.

Although it’s the most common, sometimes you’ll deal with different sorts of data. This is supported via the responseType property.

this.http.get('...', { responseType: 'text' }); //

responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'

like image 160
Muhammed Albarmavi Avatar answered Nov 01 '22 18:11

Muhammed Albarmavi