访问子文件夹中的文件AWS S3
问题描述:
我试图使用ajax请求来获取我的s3存储桶子文件夹中的所有图像文件。访问子文件夹中的文件AWS S3
我已经使用下拉菜单公开了子文件夹(请参见图片),但我仍然收到403 (Forbidden)
响应。我也尝试为该特定文件夹添加存储桶政策,但仍然没有运气。
有什么我应该做权限明智,我失踪了?我本来以为让子文件夹公开就可以完成这项工作。
这里是我的电话代码是否有帮助:
var imgUrl = "http://s3.amazonaws.com/[BUCKET NAME]/images/gallery";
var loadedImages;
var imgData = {
images: []
}
$.ajax({
url: imgUrl,
success: function getData(data) {
$(data).find("a").attr("href", function(i, val) {
if (val.match(/\.(jpe?g|png|gif)$/)) {
loadedImages = $(this).attr("href"),
imgData.images.push($(loadedImages));
console.log(imgData)
}
});
}
});
编辑:这是我的桶的权限,因为它代表:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[BUCKET NAME]/*"
},
{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::[BUCKET NAME]/images/gallery/*"
]
}
]
}
答
请与我们分享你的水桶政策,或者如果您需要提供公众阅读权限以便更新宝licy这样的:
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::example-bucket/foldername/*"
]
}
]
}
+0
将我的存储桶策略添加到原始问题 –
你可能会发现这个页面有趣https://brandonwamboldt.ca/understanding-s3-permissions-1662/ – Vorsprung
相关:https://stackoverflow.com/questions/41251450/how-to -make-ajax-call-to-aws-s3-bucket-to-get-file-name-from-folder – jarmod
请注意,“公开”仅适用于现有对象,而不适用于将来的对象。 –