我的S3 Bucket上的“点击'公开'”没有任何反应

2024-10-01 00:14:38 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我在我的bucket中点击“公开”的图片:

enter image description here

然后在弹出窗口中单击“公开”:

enter image description here

它说它成功地完成了-但是当我刷新页面时,它仍然给了我“公开”的选项,所以它看起来不起作用。当我进入我的网站时,图片仍然没有显示出来,进一步显示的图片仍然是不公开的。这是src在我的网站上使用的img

https://postr-bucket.s3.amazonaws.com/static/images/settingsIcon.png?Expires=1519249290&Signature=9eixuWMxLknf%2BAnDB1XIS30ntO8%3D&AWSAccessKeyId=AKIAIDO3PF5Y7SMSOHHA

我不认为访问密钥应该在src中,但我不确定如何更改它。我的AWS设置正常:

^{pr2}$

我也尝试过对整个bucket使用相同的“公开”选项,但是结果是一样的(表示成功,但没有公开)。在

知道为什么吗?在

enter image description here


Tags: httpssrccomimgs3bucket网站选项
2条回答

你有没有试着用.set_canned_acl('public-read')通过API公开你的文件?

    import boto
    import boto.s3.connection
    from boto.s3.key import Key 

    conn = boto.connect_s3(
        aws_access_key_id = <access_key>,
        aws_secret_access_key = <secret_key>,
        host = <host>,
        calling_format = boto.s3.connection.OrdinaryCallingFormat(),
    )

    bucket = conn.get_bucket(<bucket name>, validate=False)
    k = Key(bucket)
    k.key = <filename>
    k.set_contents_from_filename(<filename>)

    hello_key = bucket.get_key(<filename>)
    hello_key.set_canned_acl('public-read')

你说得太复杂了-既然你公开了,src应该

https://postr-bucket.s3.amazonaws.com/static/images/settingsIcon.png

你可以忘记其余的参数,他们可能导致它太失败-如果你点击我给你的链接,你会看到你的图像-我知道我可以。

编辑:查看此链接:https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

    AWS_QUERYSTRING_AUTH (optional; default is True)
    Setting AWS_QUERYSTRING_AUTH to False to remove query parameter authentication from generated URLs. 
    This can be useful if your S3 buckets are public.

相关问题 更多 >