允许Ionic应用程序通过存储桶策略访问s3存储桶

时间:2019-09-16 19:39:30

标签: ionic-framework amazon-s3

我有一个Web应用程序,可以从s3存储桶中获取视频。该存储桶具有仅允许来自某些域的访问的策略。我现在需要一个离子应用程序来访问同一存储桶,有什么办法可以将此选项添加到策略中?

这是我现在拥有的政策

{
    "Version": "2012-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originating from www.example.com.",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::bucket-name/*.mp4",
            "Condition": {
                "StringNotLike": {
                    "aws:Referer": [
                        "https://www.example.com/*"
                    ]
                }
            }
        }
    ]
}

我尝试将file://*添加到urls数组中,但无法正常工作。

1 个答案:

答案 0 :(得分:0)

您可以使用User-Agent识别来自您的应用的请求。

以下是存储桶策略的代码:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::bucket-name/*.mp4",
            "Condition": {
                "StringLike": {
                    "aws:UserAgent": "*Any name"
                }
            }
        }
    ]
}

还必须添加config.xml

<preference name="AppendUserAgent" value="Any name" />