You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React+Express应用无法渲染AWS S3图片问题求助

问题:React应用加载AWS S3图片触发内容安全策略(CSP)错误

技术栈

  • React
  • 集成AWS SDK的Express
  • 部署在fly.io平台

问题现象

尝试渲染AWS S3中的图片时,控制台抛出以下错误:

Refused to load the image 'https://say-yes-events.s3.eu-north-1.amazonaws.com/event-images/0342Andrei_profile.jpg' because it violates the following Content Security Policy directive: "img-src 'self' data:".

已尝试的解决方法

  1. 在/public目录的index.html中添加CSP meta标签:
<meta
  http-equiv="Content-Security-Policy"
  content="img-src 'self' data: https://say-yes-events.s3.eu-north-1.amazonaws.com/ 'unsafe-inline';"
/>
  1. 为AWS S3桶配置CORS规则:
[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
  1. 确认S3中对应图片内容已开启公网访问权限

内容的提问来源于stack exchange,提问作者dre_i_dashur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 15:14:52