CORS ajax用于检索一个s3对象,但不能检索另一个s3对象

时间:2017-10-27 21:55:39

标签: ajax amazon-s3 cors

我在s3上有一个存储桶,其CORS配置已正确设置。

我在同一条路径的存储桶中有两个对象,即/ minecraft_textures / blocks /

我在某些情况下成功地从这个位置请求图像,但在其他情况下不成功,我不知道为什么。

var path = "/minecraft_textures/blocks/"
var url1 = <bucket url> + path + "grass_top.png"
var url2 = <bucket url> + path + "dirt.png"

$.get(url1, function(re){ console.log(re) }) //logs the raw image data just fine
$.get(url2, function(re){ console.log(re) }) //failed to load: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<url>' is therefore not allowed access.

甚至更奇怪的是,如果我检查网络选项卡,当我查看&#34;响应&#34;时,两个图像似乎都已在XHR选项卡上获取。两个请求的选项卡。

任何人都知道案件可能是什么?

更新2:我认为更多细节在这里更好。我整个人都在粘贴&#34;将所有人复制为Har&#34 ;,无论Har意味着什么。出于某种原因,我为每个$ .ajax电话打了两个条目?如果你看一下&#34; dirt.png&#34;的第二个条目。在这种情况下,您会发现一些不同的内容:没有访问权限允许来自响应。不知道为什么它在第一个而不是第二个。

{
  "log": {
"version": "1.2",
"creator": {
  "name": "WebInspector",
  "version": "537.36"
},
"pages": [
  {
    "startedDateTime": "2017-10-27T22:17:56.517Z",
    "id": "page_14",
    "title": "<my url>/schematics/balthatrix-blocktest?remix=balthatrix-blocktest",
    "pageTimings": {
      "onContentLoad": 845.4170000040904,
      "onLoad": 951.2460000114515
    }
  }
],
"entries": [
  {
    "startedDateTime": "2017-10-27T22:50:06.775Z",
    "time": 298.45049100206234,
    "request": {
      "method": "OPTIONS",
      "url": "<bucket>/minecraft_textures/blocks/grass_top.png",
      "httpVersion": "HTTP/1.1",
      "headers": [
        {
          "name": "Access-Control-Request-Method",
          "value": "GET"
        },
        {
          "name": "Origin",
          "value": "<my url>"
        },
        {
          "name": "Accept-Encoding",
          "value": "gzip, deflate, br"
        },
        {
          "name": "Host",
          "value": "s3.amazonaws.com"
        },
        {
          "name": "Accept-Language",
          "value": "en-US,en;q=0.8"
        },
        {
          "name": "User-Agent",
          "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
        },
        {
          "name": "Accept",
          "value": "*/*"
        },
        {
          "name": "Referer",
          "value": "<my url>/schematics/balthatrix-blocktest?remix=balthatrix-blocktest"
        },
        {
          "name": "Connection",
          "value": "keep-alive"
        },
        {
          "name": "Access-Control-Request-Headers",
          "value": "x-csrf-token"
        }
      ],
      "queryString": [],
      "cookies": [],
      "headersSize": 563,
      "bodySize": 0
    },
    "response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "HTTP/1.1",
      "headers": [
        {
          "name": "Date",
          "value": "Fri, 27 Oct 2017 22:50:09 GMT"
        },
        {
          "name": "Server",
          "value": "AmazonS3"
        },
        {
          "name": "x-amz-request-id",
          "value": "70FC2ED888B8C973"
        },
        {
          "name": "Vary",
          "value": "Origin, Access-Control-Request-Headers, Access-Control-Request-Method"
        },
        {
          "name": "Access-Control-Allow-Methods",
          "value": "GET"
        },
        {
          "name": "Access-Control-Allow-Origin",
          "value": "<my url>"
        },
        {
          "name": "Access-Control-Allow-Credentials",
          "value": "true"
        },
        {
          "name": "Access-Control-Allow-Headers",
          "value": "x-csrf-token"
        },
        {
          "name": "Content-Length",
          "value": "0"
        },
        {
          "name": "x-amz-id-2",
          "value": "u7BycB76EqAkGTdsLnZqxSMQV/jNZz+rIP/+kxjNFwuVOq6U7rYT6KCrFlLOs17YT0uT5fePz+g="
        }
      ],
      "cookies": [],
      "content": {
        "size": 0,
        "mimeType": "text/plain",
        "compression": 0
      },
      "redirectURL": "",
      "headersSize": 467,
      "bodySize": 0,
      "_transferSize": 467
    },
    "cache": {},
    "timings": {
      "blocked": 0.40449093305505796,
      "dns": 0.00400003045797398,
      "ssl": 139.662000001408,
      "connect": 207.02500001061736,
      "send": 0.24299998767600073,
      "wait": 89.46699998341546,
      "receive": 1.3070000568404794,
      "_blocked_queueing": 0.49100001342594624
    },
    "serverIPAddress": "<some ip>",
    "connection": "1806524",
    "pageref": "page_14"
  },
  {
    "startedDateTime": "2017-10-27T22:50:07.075Z",
    "time": 0.31571604893542826,
    "request": {
      "method": "GET",
      "url": "<bucket>/minecraft_textures/blocks/grass_top.png",
      "httpVersion": "http/1.1",
      "headers": [
        {
          "name": "Accept",
          "value": "*/*"
        },
        {
          "name": "Referer",
          "value": "<my url>/schematics/balthatrix-blocktest?remix=balthatrix-blocktest"
        },
        {
          "name": "Origin",
          "value": "<my url>"
        },
        {
          "name": "X-CSRF-Token",
          "value": "iJwlAO3xnOW5NhSmqT01iU0WgzqWlVw8EhEFFqQWeBU="
        },
        {
          "name": "User-Agent",
          "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
        }
      ],
      "queryString": [],
      "cookies": [],
      "headersSize": -1,
      "bodySize": 0
    },
    "response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "http/1.1",
      "headers": [
        {
          "name": "Date",
          "value": "Fri, 27 Oct 2017 21:03:20 GMT"
        },
        {
          "name": "Last-Modified",
          "value": "Mon, 16 Oct 2017 19:10:08 GMT"
        },
        {
          "name": "Server",
          "value": "AmazonS3"
        },
        {
          "name": "x-amz-request-id",
          "value": "C6C68D249C9D84D8"
        },
        {
          "name": "ETag",
          "value": "\"8a5e27ad67530942459115a70f12d1ea\""
        },
        {
          "name": "Vary",
          "value": "Origin, Access-Control-Request-Headers, Access-Control-Request-Method"
        },
        {
          "name": "Access-Control-Allow-Methods",
          "value": "GET"
        },
        {
          "name": "x-amz-version-id",
          "value": "sRu5xgTWXMZzDHnI2gI8fbkPHNFzaVl5"
        },
        {
          "name": "Access-Control-Allow-Origin",
          "value": "http://52.203.199.244"
        },
        {
          "name": "Access-Control-Max-Age",
          "value": "3000"
        },
        {
          "name": "Access-Control-Allow-Credentials",
          "value": "true"
        },
        {
          "name": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "name": "Content-Type",
          "value": "image/png"
        },
        {
          "name": "Content-Length",
          "value": "560"
        },
        {
          "name": "x-amz-id-2",
          "value": "/+UkjBDbuCeMmIi5bYdW4TRC+8JRpu/gs60OxguEWzKqZvxGFAM66YhBKcgrEO7EM1OO9oMfbT8="
        }
      ],
      "cookies": [],
      "content": {
        "size": 560,
        "mimeType": "image/png"
      },
      "redirectURL": "",
      "headersSize": -1,
      "bodySize": 0,
      "_transferSize": 0
    },
    "cache": {},
    "timings": {
      "blocked": 0.11871596728451544,
      "dns": -1,
      "ssl": -1,
      "connect": -1,
      "send": 0,
      "wait": 0.9469999931752682,
      "receive": 1.2500000884756446,
      "_blocked_queueing": 0.7160000968724489
    },
    "serverIPAddress": "<some ip>",
    "_fromCache": "disk",
    "pageref": "page_14"
  },
  {
    "startedDateTime": "2017-10-27T22:51:04.821Z",
    "time": 313.95750115136616,
    "request": {
      "method": "OPTIONS",
      "url": "<bucket>/minecraft_textures/blocks/dirt.png",
      "httpVersion": "HTTP/1.1",
      "headers": [
        {
          "name": "Access-Control-Request-Method",
          "value": "GET"
        },
        {
          "name": "Origin",
          "value": "<my url>"
        },
        {
          "name": "Accept-Encoding",
          "value": "gzip, deflate, br"
        },
        {
          "name": "Host",
          "value": "s3.amazonaws.com"
        },
        {
          "name": "Accept-Language",
          "value": "en-US,en;q=0.8"
        },
        {
          "name": "User-Agent",
          "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
        },
        {
          "name": "Accept",
          "value": "*/*"
        },
        {
          "name": "Referer",
          "value": "<my url>/schematics/balthatrix-blocktest?remix=balthatrix-blocktest"
        },
        {
          "name": "Connection",
          "value": "keep-alive"
        },
        {
          "name": "Access-Control-Request-Headers",
          "value": "x-csrf-token"
        }
      ],
      "queryString": [],
      "cookies": [],
      "headersSize": 558,
      "bodySize": 0
    },
    "response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "HTTP/1.1",
      "headers": [
        {
          "name": "Date",
          "value": "Fri, 27 Oct 2017 22:51:07 GMT"
        },
        {
          "name": "Server",
          "value": "AmazonS3"
        },
        {
          "name": "x-amz-request-id",
          "value": "C92F63A2987F21C6"
        },
        {
          "name": "Vary",
          "value": "Origin, Access-Control-Request-Headers, Access-Control-Request-Method"
        },
        {
          "name": "Access-Control-Allow-Methods",
          "value": "GET"
        },
        {
          "name": "Access-Control-Allow-Origin",
          "value": "<my url>"
        },
        {
          "name": "Access-Control-Allow-Credentials",
          "value": "true"
        },
        {
          "name": "Access-Control-Allow-Headers",
          "value": "x-csrf-token"
        },
        {
          "name": "Content-Length",
          "value": "0"
        },
        {
          "name": "x-amz-id-2",
          "value": "WRb922Ftmq02e9mu3R49WBnPoINk8lQQjDteUaxIWZQ8TgONwFcX6pdVBrTszSG2rGbCor5bmf8="
        }
      ],
      "cookies": [],
      "content": {
        "size": 0,
        "mimeType": "text/plain",
        "compression": 0
      },
      "redirectURL": "",
      "headersSize": 467,
      "bodySize": 0,
      "_transferSize": 467
    },
    "cache": {},
    "timings": {
      "blocked": 0.2805009202565999,
      "dns": 10.52800007164477,
      "ssl": 135.48900000751038,
      "connect": 212.14700001291897,
      "send": 0.23600005079100583,
      "wait": 89.50200001709158,
      "receive": 1.26400007866323,
      "_blocked_queueing": 0.5010000895708799
    },
    "serverIPAddress": "<my url>",
    "connection": "1806575",
    "pageref": "page_14"
  },
  {
    "startedDateTime": "2017-10-27T22:51:05.126Z",
    "time": 0.13165004481561482,
    "request": {
      "method": "GET",
      "url": "<bucket>/minecraft_textures/blocks/dirt.png",
      "httpVersion": "http/1.1",
      "headers": [
        {
          "name": "Accept",
          "value": "*/*"
        },
        {
          "name": "Referer",
          "value": "<my url>/schematics/balthatrix-blocktest?remix=balthatrix-blocktest"
        },
        {
          "name": "Origin",
          "value": "<my url>"
        },
        {
          "name": "X-CSRF-Token",
          "value": "iJwlAO3xnOW5NhSmqT01iU0WgzqWlVw8EhEFFqQWeBU="
        },
        {
          "name": "User-Agent",
          "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
        }
      ],
      "queryString": [],
      "cookies": [],
      "headersSize": -1,
      "bodySize": 0
    },
    "response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "http/1.1",
      "headers": [
        {
          "name": "Date",
          "value": "Fri, 27 Oct 2017 18:19:13 GMT"
        },
        {
          "name": "Last-Modified",
          "value": "Mon, 16 Oct 2017 19:09:06 GMT"
        },
        {
          "name": "Server",
          "value": "AmazonS3"
        },
        {
          "name": "x-amz-request-id",
          "value": "A040F0B8DCB15C3D"
        },
        {
          "name": "ETag",
          "value": "\"f73260a4acf91df3ec2c28532af39251\""
        },
        {
          "name": "Content-Type",
          "value": "image/png"
        },
        {
          "name": "Content-Length",
          "value": "266"
        },
        {
          "name": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "name": "x-amz-version-id",
          "value": "McnxZQiP5deM8adiFKHluJwJAKG1ebTg"
        },
        {
          "name": "x-amz-id-2",
          "value": "Mv0fDossndy+iqTweUfbugP314hI+qR73mFhHnhROZlIg1WiN4Hm5e0LLzx/c1o/kw3is0gSF0o="
        }
      ],
      "cookies": [],
      "content": {
        "size": 266,
        "mimeType": "image/png"
      },
      "redirectURL": "",
      "headersSize": -1,
      "bodySize": 0,
      "_transferSize": 0
    },
    "cache": {},
    "timings": {
      "blocked": 0.11964997486211318,
      "dns": -1,
      "ssl": -1,
      "connect": -1,
      "send": 0,
      "wait": 0.8120000129565601,
      "receive": 1.2000000569969416,
      "_blocked_queueing": 0.6500000599771738
    },
    "serverIPAddress": "<raw ip>",
    "_fromCache": "disk",
    "pageref": "page_14"
  }
]}
}

0 个答案:

没有答案