我有一个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权限问题,还是还有其他问题?
答案 0 :(得分:1)
您似乎正在尝试创建没有写入权限的文件。
最好不要将副本保存到应用服务器。如果你能建议你从内存中的对象返回操作/内容/其他内容。
但是如果由于某种原因你确实需要本地文件,你应该在/ tmp
中拥有写权限