Access to Image from origin 'null' has been blocked by CORS policy Access to Image from origin 'null' has been blocked by CORS policy javascript javascript

Access to Image from origin 'null' has been blocked by CORS policy


You're running into a CORS error.

Trying to access your file using the local file system doesn't work in your case.

Origin is null because it's your local file system. Could you possibly host this png file?

Suggestion:

Host these files to an AWS S3 bucket instead. Then you can use the http protocol rather than the file protocol. OR setup some http server on your local system and use http to your localhost to serve the files from if you want to keep everything local.

More Reading:

How CORS Works


The problem was actually solved by providing crossOrigin: null to OpenLayers OSM source:

var newLayer = new ol.layer.Tile({source: new ol.source.OSM({    url: 'E:/Maperitive/Tiles/vychod/{z}/{x}/{y}.png',    crossOrigin: null    })});


Under the covers there will be some form of URL loading request. You can't load images or any other content via this method from a local file system.

Your image needs to be loaded via a web server, so accessed via a proper http URL.