2

I can succesfully use a HTTP GET to retrieve an image via services like Postman and Hurl.it.

I'm now trying to obtain the same image via Angular HttpClient as blob. Code is basically as is:

this.http.get('via.placeholder.com/200x200',{ responseType: 'blob'}).subscribe(data => this.d = data);

Whether I use map and subscribe, I can't retrieve the image data. I always get the same CORS error in Chrome:

Failed to load via.placeholder.com/200x200: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 405

Now I know the "why is this working with Postman but not in my code" has been answered here.

That said, is there still a way, using javascript/angular and without using a proxy, to simply get an image from a website via HTTP GET?

Actolia
  • 125
  • 2
  • 7
  • To allow cross domain request, the server should add Access-Control-Allow-Origin header to response, and it's value should be * to allow any domain or specific domain name to allow that specific domain. – AjinkyaBhagwat Feb 14 '18 at 08:20
  • If the server does not have the CORS headers set, the only solution is using a proxy – David Feb 14 '18 at 08:26
  • as a workaround, you can use this extension https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi that allows you to obtain it, at least for testing pruposes – No One Dec 11 '18 at 12:20

0 Answers0