访问R2时如何避免COR问题?

问题描述 投票:0回答:1

使用 exif-js 库时出现以下 COR 错误:

Failed to load resource: Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. Status code: 200

令人困惑的是,使用

img
标签时图像加载正常。此外,我已设置 R2 COR 策略如下:

[
  {
    "AllowedOrigins": [
      "http://localhost:3000",
      "http://127.0.0.1:3000",
      "*"
    ],
    "AllowedMethods": [
      "GET",
      "HEAD",
      "POST",
      "PUT",
      "DELETE"
    ],
    "AllowedHeaders": [
      "Authorization",
      "Content-Type",
      "Origin",
      "Accept",
      "X-Requested-With",
      "Access-Control-Request-Method",
      "Access-Control-Request-Headers"
    ],
    "ExposeHeaders": [
      "ETag",
      "Cache-Control",
      "Content-Length",
      "Content-Range",
      "Content-Type",
      "Date",
      "Last-Modified"
    ]
  }
]

应该允许从任何地方访问。我做错了什么?

这是一个最小的可重现示例。 img 加载正常,但在使用 exif 库时出现 CORs 错误:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>EXIF Data Viewer</title>
    <script src="https://cdn.jsdelivr.net/npm/exif-js"></script>
</head>
<body>
    <img src="https://someurl.com/img.jpeg" id="img" style="max-width: 500px;">

    <script>
        console.log('setting hook')
        window.onload = function() {
            const img = document.getElementById('img');
            EXIF.getData(img, function() {
                const exifData = EXIF.getAllTags(this);
                console.log('EXIF Data:', exifData);
            });
        };
    </script>
</body>
</html>

javascript amazon-s3 cors
1个回答
0
投票

非常简单的答案哈哈。我只需按 control-shift-R 即可删除浏览器的缓存。

© www.soinside.com 2019 - 2024. All rights reserved.