2014-10-01 151 views
1

我们的网站有一个问题,与铬,从亚马逊S3加载图像与crossOrigin属性设置在“匿名”Cross Origin amazon S3 not working using chrome

我们S3服务器设置好的用:

`

<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
    <CORSRule> 
     <AllowedOrigin>*</AllowedOrigin> 
     <AllowedMethod>GET</AllowedMethod> 
     <AllowedMethod>HEAD</AllowedMethod> 
     <AllowedMethod>POST</AllowedMethod> 
     <MaxAgeSeconds>3000</MaxAgeSeconds> 
     <ExposeHeader>x-amz-server-side-encryption</ExposeHeader> 
     <ExposeHeader>x-amz-request-id</ExposeHeader> 
     <ExposeHeader>x-amz-id-2</ExposeHeader> 
     <AllowedHeader>*</AllowedHeader> 
    </CORSRule> 
</CORSConfiguration> 

`

我使用canvg.js以创建从具有远程图像的SVG画布(亚马逊S3服务器)但Chrome浏览器返回“否访问控制允许来源标题存在于请求的资源中。错误后执行该代码:

this.img = document.createElement('img'); 
      var self = this; 
      this.img.onload = function() { self.loaded = true; } 
      this.img.onerror = function() { if (typeof(console) != 'undefined')            
      console.log('ERROR: image "' + href + '" not found'); self.loaded = true; } } 
      if (svg.opts['useCORS'] == true) { 
           this.img.crossOrigin = 'Anonymous'; } 
      this.img.src = href; 

在Firefox和IE浏览器这不会造成任何问题。

+0

你“认为”这不是S3设置的问题?你不应该发布你的S3 CORS配置吗? – 2014-10-01 15:12:16

+0

我刚刚添加了它...我认为这不是S3设置的问题,因为在其他浏览器中它可以工作 – user3642612 2014-10-01 15:44:25

回答

1

这是Chrome缓存请求的问题。 Here是关于这个话题的讨论。

只需将以下内容添加到您试图访问MDN here所记录的其他域crossorigin="anonymous"资源的所有HTML标记中。