2

I had used ionic image loader plugin, Link: https://www.npmjs.com/package/ionic-image-loader

When I try to load an image using "img-loader" as below

<img-loader src="https://path.to/my/image.jpg" useImg></img-loader>

It gives CORS issue for accessing an image path.

Displaying the following issue!

Failed to load https://path.to/my/image.jpg: 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:8100' is therefore not allowed access.

while whole other images in normal "img" tags works and loads fine.

Even Apis works fine from localhost origin because 'Access-Control-Allow-Origin' is set to '*' on the server end.

But at the time of using ionic image loader, image URL doesn't pass access control check in its preflight request.

nishil bhave
  • 582
  • 1
  • 5
  • 17
  • _“Even Apis works fine from localhost origin because 'Access-Control-Allow-Origin' is set to '*' on the server end”_ - what “server end”? Are you talking about the server behind the `path.to` “domain” here, or something else? – CBroe Apr 11 '18 at 13:14
  • Yes, I'm talking about server behind path.to domain – nishil bhave Apr 11 '18 at 13:47
  • And for which request methods? (A preflight request is OPTIONS.) – CBroe Apr 11 '18 at 14:29
  • Normal Apis preflight request pass the access check, But when I use Ionic image loader than image-URL makes a request with method 'options'(Preflight) and gets a CORS issue. – nishil bhave Apr 12 '18 at 09:47
  • Well then you have to fix your server-side setup, so that it properly responds to a preflight request for an image as well ... – CBroe Apr 12 '18 at 09:53
  • Yes! but what exactly needs to be done on server-side to allow images? That's I'm searching right now. Thanks for your help. – nishil bhave Apr 12 '18 at 10:28
  • What webserver are you using? For Apache, you can find an approach here: https://stackoverflow.com/a/42558499/1427878 – CBroe Apr 12 '18 at 10:33
  • Im using apache, Thanks! – nishil bhave Apr 12 '18 at 10:51

0 Answers0