使用预签名 URL 时 AWS S3 访问被拒绝

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

当我尝试从后端生成的签名 URL 获取图像时遇到错误。

这是控制台中出现的错误:

Image of the error on the console

当我进入该链接时,会出现以下内容:

Image of the content when joining the link of the error

这就是我在服务器中所做的事情,只是从数据库中获取所有帖子,对帖子进行循环并为每个帖子生成签名 URL。

const displayAllPosts = async (req, res) => {
  try {
    const posts = await prisma.post.findMany();

    for (const post of posts) {
      const getObjectParams = {
        Bucket: bucketName,
        Key: post.image,
      };

      const command = new GetObjectCommand(getObjectParams);
      const url = await getSignedUrl(s3, command);

      post.imageUrl = url;
    }
    res.json(posts);
  } catch (error) {
    console.log(error);
  }
};

这是我的 IAM 政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::----/*"
        }
    ]
}

我尝试重新制作 s3 存储桶、IAM 用户和 IAM 策略,但没有解决方案。

我只想获取图像并将其显示在明信片中。

reactjs amazon-web-services express amazon-s3
1个回答
0
投票

我仍然没有解决问题,我感谢任何帮助:P

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