Strapi v4 - 上传到 S3 的图像不显示在媒体库中

Strapi v4 - images uploaded to S3 are not displayed in media gallery

我正在试用新的 Strapi v4。我安装了 provider-upload-aws-s3 以将我的图像上传到 S3 并对其进行配置。我确实在 S3 存储桶中看到了我的图像,但在媒体库中看不到它们。我检查了请求,发现我收到此错误:

Content Security Policy: The page’s settings blocked the loading of a resource at {my img URL}.

当尝试直接在浏览器中使用相同的 URL 获取图像并且正在加载图像时。

我认为这与此警告有关(引用自 Strapi 文档):

Strapi has a default Security Middleware that has a very strict contentSecurityPolicy that limits loading images and media to "'self'" only, see the example configuration on the provider page or take a look at our middleare documentation for more information.

但我不确定如何处理它以及如何覆盖它。那么如何让上传到S3的图片出现在媒体库中呢?

好吧,在这一点上我真的确定这是一个错误并在 Strapi Github 问题上报告了它。但是根据 this answer 我收到了一些必须在 middlewares.js 文件中完成的配置:

module.exports = [
  "strapi::errors",
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "your-s3-url",
          ],
          "media-src": ["'self'", "data:", "blob:"],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  "strapi::cors",
  "strapi::poweredBy",
  "strapi::logger",
  "strapi::query",
  "strapi::body",
  "strapi::favicon",
  "strapi::public",
];

我将 your-s3-url 更改为 *.amazonaws.com 然后一切终于成功了。