简体   繁体   English

Azure 存储 Blob CORS 错误

[英]Azure Storage Blob CORS errors

I have an Azure Storage Account (classic) and I enabled CORS through the portal in this way:我有一个 Azure 存储帐户(经典),并以这种方式通过门户启用了 CORS:

在此处输入图像描述

Now I have a Flutter Web App (PWA) that needs to get some images from this storage, but it gets CORS errors.现在我有一个 Flutter Web 应用程序 (PWA) 需要从这个存储中获取一些图像,但它得到 CORS 错误。

I also tried with a test web page with a simple jquery ajax call and I gets the same errors.我还尝试了一个测试 web 页面和一个简单的 jquery ajax 调用,我得到了同样的错误。 This is the jquery code:这是 jquery 代码:

$.ajax({
        url: 'https://xxxx.blob.core.windows.net/test.jpg',
        type: 'get',
        success: function(data, status) {
            console.log("Status: "+status+"\nData: "+data);
        },
        error: function (result) {
            console.log(result);
        }           
     });

The error message is:错误信息是:

Access to XMLHttpRequest at 'https://xxxx.blob.core.windows.net/test.jpg' from origin 'https://zzz.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. CORS 政策已阻止从源“https://zzz.azurewebsites.net”访问“https://xxxx.blob.core.windows.net/test.jpg”处的 XMLHttpRequest:否“访问控制允许” -Origin' header 存在于请求的资源上。

How can I add the Response Header: access-control-allow-origin: *如何添加响应 Header: access-control-allow-origin: *

Thanks.谢谢。

As discussed in the chat , your CORS configuration is perfectly fine.正如chat中所讨论的,您的 CORS 配置非常好。 The issue you are running into is because the browser had cached the CORS settings.您遇到的问题是因为浏览器缓存了 CORS 设置。 Two things we discovered:我们发现了两件事:

  1. CORS settings max age was set at a very high value (86400 seconds) that would have made the browser cache the CORS settings for a longer duration. CORS 设置的最大年龄设置为非常高的值(86400 秒),这会使浏览器缓存 CORS 设置的时间更长。 Deleting the CORS settings and recreating it with lower max age value along with deleting browser cache will fix that.删除 CORS 设置并使用较低的最大年龄值重新创建它以及删除浏览器缓存将解决该问题。

  2. It is always helpful to try the AJAX request in a 2nd browser just in case the 1st browser has cached the CORS settings.在第二个浏览器中尝试 AJAX 请求总是有帮助的,以防第一个浏览器缓存了 CORS 设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM