2

我有一个grails 2.1.1应用程序,它正在访问使用Grails-AWS插件访问的s3存储区中存储的图像。从Grails上获取S3上的图像时'权限被拒绝'

当我使用“grails run-app”并且服务器是localhost:8080/myApp时,一切正常。我可以放置并获取没有问题的文件。

但是,当我将WAR文件部署到Amazon弹性魔豆,我得到试图获取图像时出现以下错误:

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

我觉得这个临客:https://forums.aws.amazon.com/message.jspa?messageID = 205071可能会有所帮助。只是不确定。 – coderLMN

回答

1

看来你正在尝试创建文件,你没有写权限。

最好不要将副本保存到应用服务器。如果你能建议你从内存中的对象返回操纵/内容/任何东西。

但是,如果你真的需要在本地文件由于某些原因,你应该有写权限在/ tmp中

+0

你说的都对。问题不在于S3的权限,而在于我的本地文件系统。你也是对的,我不需要写任何东西。我的新Getpicture中方法现在看起来是这样的:。\t图片Getpicture中(){ \t \t \t \t高清URL = aws.s3()上( “mybucket”)URL(图像, “MyFolder文件”) \t \t \t \t Toolkit.getDefaultToolkit()。createImage(url); \t}感谢您的帮助! –