How do I client-side upload a viewable file to Amazon S3?

前端 未结 7 1371
别那么骄傲
别那么骄傲 2020-12-13 15:20

Let me start of by saying that I am normally very reluctant to post this questions as I always feel that there\'s an answer to everything SOMEWHERE on the internet. After sp

7条回答
  •  不知归路
    2020-12-13 16:09

    It sounds like you don't really need a signed URL, just that you want your uploads to be publicly viewable. If that's the case, you just need to go to the AWS console, choose the bucket you want to configure, and click on permissions. Then click the button that says 'add bucket policy' and input the following rule:

    {
        "Version": "2008-10-17",
        "Id": "http referer policy example",
        "Statement": [
            {
                "Sid": "readonly policy",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": "arn:aws:s3:::BUCKETNAME/*"
            }
        ]
    }
    

    where BUCKETNAME should be replaced with your own bucket's name. The contents of that bucket will be readable by anyone now, provided they have a direct link to a specific file.

提交回复
热议问题