我想在reactjs应用程序中使用Amazon S3映像。当我使用以下代码时,我收到了禁止错误:
<img src="http://huddlon.s3.amazonaws.com/profilepictures/profile_pic_1_2016_20_02_21_08_22_928182822.jpg" alt="huddlon" className="avatar"/>
答案 0 :(得分:1)
您需要允许匿名用户访问此图片。您可以在aws控制台上手动设置它:
或者您可以以编程方式执行此操作。请参阅示例How to do it in Java。如果您的后端使用其他语言进行编码,请进行Google搜索,您可以轻松地在网络上找到该语言的示例。
注意:根据您的React项目的托管位置,您可能还需要启用CORS。 See the aws documentation for a detailed explanation.
答案 1 :(得分:0)
我在 GitHub 上创建了一个概念验证项目,以详细介绍在 AWS S3 和 CloudFront 上托管 ReactJS 的几个细节。 The Wiki 应该解释一切。
该项目包括 CloudFormation 模板和示例代码。