<i id='Kp8q6'><tr id='Kp8q6'><dt id='Kp8q6'><q id='Kp8q6'><span id='Kp8q6'><b id='Kp8q6'><form id='Kp8q6'><ins id='Kp8q6'></ins><ul id='Kp8q6'></ul><sub id='Kp8q6'></sub></form><legend id='Kp8q6'></legend><bdo id='Kp8q6'><pre id='Kp8q6'><center id='Kp8q6'></center></pre></bdo></b><th id='Kp8q6'></th></span></q></dt></tr></i><div id='Kp8q6'><tfoot id='Kp8q6'></tfoot><dl id='Kp8q6'><fieldset id='Kp8q6'></fieldset></dl></div>
    <bdo id='Kp8q6'></bdo><ul id='Kp8q6'></ul>
    <legend id='Kp8q6'><style id='Kp8q6'><dir id='Kp8q6'><q id='Kp8q6'></q></dir></style></legend>

    1. <tfoot id='Kp8q6'></tfoot>
    2. <small id='Kp8q6'></small><noframes id='Kp8q6'>

        CORS 策略已阻止从源“null"访问图像

        时间:2023-09-03
      1. <tfoot id='urKi0'></tfoot>
        1. <i id='urKi0'><tr id='urKi0'><dt id='urKi0'><q id='urKi0'><span id='urKi0'><b id='urKi0'><form id='urKi0'><ins id='urKi0'></ins><ul id='urKi0'></ul><sub id='urKi0'></sub></form><legend id='urKi0'></legend><bdo id='urKi0'><pre id='urKi0'><center id='urKi0'></center></pre></bdo></b><th id='urKi0'></th></span></q></dt></tr></i><div id='urKi0'><tfoot id='urKi0'></tfoot><dl id='urKi0'><fieldset id='urKi0'></fieldset></dl></div>
            <legend id='urKi0'><style id='urKi0'><dir id='urKi0'><q id='urKi0'></q></dir></style></legend>

                  <bdo id='urKi0'></bdo><ul id='urKi0'></ul>
                    <tbody id='urKi0'></tbody>

                  <small id='urKi0'></small><noframes id='urKi0'>

                  本文介绍了CORS 策略已阻止从源“null"访问图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在 OpenLayers 3 中有 JavaScript 应用程序,我的基础层是从本地图块创建的.我只在我的电脑上工作,所以我不知道为什么会出现 CORS 错误.

                  I have JavaScript application in OpenLayers 3, and my base layer is created from local tiles. I work only in my computer so I do not know why I have CORS error.

                      var newLayer = new ol.layer.Tile({
                      source: new ol.source.OSM({
                          url: 'E:/Maperitive/Tiles/vychod/{z}/{x}/{y}.png'
                      })
                  });
                  var schladming = [21.6187, 48.7327]; // longitude first, then latitude
                  // since we are using OSM, we have to transform the coordinates...
                  var schladmingWebMercator = ol.proj.fromLonLat(schladming);
                  
                  var map = new ol.Map({
                      layers: [
                          newLayer
                      ],
                      controls: [],
                      target: 'mapid',
                      view: new ol.View({
                          center: schladmingWebMercator,
                          zoom: 10,
                          minZoom: 10,
                          maxZoom: 14
                      })
                  });
                  

                  来自控制台的错误消息:

                  error message from console:

                  从源 null 访问 file:///E:/​​Maperitive/Tiles/vychod/10/573/352.png 的图像已被 CORS 阻止策略:无效响应.Origin null 因此不允许访问.

                  Access to Image at file:///E:/Maperitive/Tiles/vychod/10/573/352.png from origin null has been blocked by CORS policy: Invalid response. Origin null is therefore not allowed access.

                  当我双击图像 URL 时,图像被打开.有什么想法有什么问题吗?我以前从未遇到过这种错误.

                  When I double-click on image URL, image is opened. Any ideas what is wrong? I never had that error before.

                  推荐答案

                  您遇到了 CORS 错误.

                  You're running into a CORS error.

                  在您的情况下,尝试使用本地文件系统访问您的文件不起作用.

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

                  Origin 为空,因为它是您的本地文件系统.你能托管这个 png 文件吗?

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

                  改为将这些文件托管到 AWS S3 存储桶.然后你可以使用 http 协议而不是 file 协议.或者在您的本地系统上设置一些 http 服务器并使用 http 到您的 localhost 来提供文件,如果您想将所有内容都保留在本地.

                  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.

                  CORS 的工作原理

                  这篇关于CORS 策略已阻止从源“null"访问图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Wikipedia API 支持 CORS 还是仅支持 JSONP? 下一篇:Socket.IO 中的跨域连接

                  相关文章

                  最新文章

                  1. <tfoot id='RQPS7'></tfoot>
                    <i id='RQPS7'><tr id='RQPS7'><dt id='RQPS7'><q id='RQPS7'><span id='RQPS7'><b id='RQPS7'><form id='RQPS7'><ins id='RQPS7'></ins><ul id='RQPS7'></ul><sub id='RQPS7'></sub></form><legend id='RQPS7'></legend><bdo id='RQPS7'><pre id='RQPS7'><center id='RQPS7'></center></pre></bdo></b><th id='RQPS7'></th></span></q></dt></tr></i><div id='RQPS7'><tfoot id='RQPS7'></tfoot><dl id='RQPS7'><fieldset id='RQPS7'></fieldset></dl></div>
                    <legend id='RQPS7'><style id='RQPS7'><dir id='RQPS7'><q id='RQPS7'></q></dir></style></legend>

                        <bdo id='RQPS7'></bdo><ul id='RQPS7'></ul>

                    1. <small id='RQPS7'></small><noframes id='RQPS7'>