我有一个grails 2.1.1应用程序,该应用程序正在访问存储在s3上存储桶中的图像,而我正在使用Grails-AWS插件进行访问。
当我使用“grails run-app”并且服务器是localhost:8080 / myApp时,一切正常。我可以毫无问题地放置和获取文件。
但是,当我将war文件部署到Amazon Elastic Beanstalk时,尝试获取镜像时出现以下错误:
java.io.FileNotFoundException: 90916.png (Permission denied)
at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
at java.io.FileOutputStream.<init>(FileOutputStream.java:160)
at com.sommelier.domain.core.MyDomainObject.getPicture(MyDomainObject.groovy:145)
这是我的代码,用于获取引发错误的图像:
File getPicture() {
def url = aws.s3().on("mybucket").url(image, "myfoldername")
File imageFile = new File(image)
def fileOutputStream = new FileOutputStream(imageFile)
def out = new BufferedOutputStream(fileOutputStream)
out << new URL(url).openStream()
out.close()
return imageFile
}
我已在s3存储桶上设置了尽可能大的权限。我使用了“添加更多权限”按钮,并添加了所有可能的选项。
这是我的存储桶策略:
{
"Version": "2008-10-17",
"Id": "Policy1355414697022",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mybucket/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::mybucket/*"
}
]
}
而我的CORS配置:
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
有什么想法吗?这是S3权限问题,还是还有其他问题?
最佳答案
似乎您正在尝试创建没有写权限的文件。
最好不要将副本保存到应用服务器。如果可以的话,我建议您从内存中的对象返回操作/内容/任何内容。
但是,如果由于某些原因确实确实需要本地文件,则应该在/ tmp中具有写权限
关于grails - 从Grails获取S3上的图像时“权限被拒绝”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034726/