2013-06-01 12 views
0

我刚刚在我的托管在heroku上的rails应用程序中实现了回形针。该应用程序似乎将图像连接并上传到s3。以下是我在应用中提交表单时的一些日志示例:图像似乎被添加到存储桶中,无法在我的应用程序中查看

2013-06-01T17:52:45.112448+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"2/vRFLrAnBnokNwohVfMhG74d3HN0/GTwype2jGJm9w=", "illustration"=>{"name"=>"Test", "illustrator"=>"Test", "image"=>#<ActionDispatch::Http::UploadedFile:0x000000050d9a58 @original_filename="DEISIGN_Cover_Illustration.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"illustration[image]\"; filename=\"DEISIGN_Cover_Illustration.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130601-12-v7uo9s>>, "edition_id"=>"17", "tag_list"=>"Test", "description"=>"Test"}, "commit"=>"Update Illustration", "id"=>"199"} 
2013-06-01T17:52:45.113280+00:00 app[web.1]: [AWS S3 200 0.424977 0 retries] head_object(:bucket_name=>"haggard",:key=>"illustrations/images/000/000/199/original/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:45.113496+00:00 app[web.1]: 
2013-06-01T17:52:45.113496+00:00 app[web.1]: [AWS S3 200 0.085094 0 retries] head_object(:bucket_name=>"haggard",:key=>"illustrations/images/000/000/199/thumb/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:45.113496+00:00 app[web.1]: 
2013-06-01T17:52:45.624956+00:00 app[web.1]: [AWS S3 204 0.099689 0 retries] delete_object(:bucket_name=>"haggard",:key=>"illustrations/images/000/000/199/original/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:45.624956+00:00 app[web.1]: 
2013-06-01T17:52:45.715606+00:00 app[web.1]: [AWS S3 204 0.09001 0 retries] delete_object(:bucket_name=>"haggard",:key=>"illustrations/images/000/000/199/thumb/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:45.715606+00:00 app[web.1]: 
2013-06-01T17:52:46.835310+00:00 app[web.1]: [AWS S3 200 1.116787 0 retries] put_object(:acl=>:public_read,:bucket_name=>"haggard",:content_length=>575121,:content_type=>"image/jpeg",:data=>Paperclip::UploadedFileAdapter: DEISIGN_Cover_Illustration.jpg,:key=>"illustrations/images/000/000/199/original/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:46.835310+00:00 app[web.1]: 
2013-06-01T17:52:47.011793+00:00 app[web.1]: [AWS S3 200 0.173532 0 retries] put_object(:acl=>:public_read,:bucket_name=>"haggard",:content_length=>6096,:content_type=>"image/jpeg",:data=>Paperclip::FileAdapter: DEISIGN_Cover_Illustration20130601-12-6ldegn20130601-12-1ytcjd0,:key=>"illustrations/images/000/000/199/thumb/DEISIGN_Cover_Illustration.jpg") 
2013-06-01T17:52:47.011793+00:00 app[web.1]: 
2013-06-01T17:52:47.020929+00:00 app[web.1]: Redirected to http://visualhaggard.org/illustrations/199 

我上传的图像出现在我的S3存储桶控制台中。

我的看法使用@illustration.image.url来获取要显示的图像。

我没有设置图像的任何地方的权限。他们是否自动设置为应用程序上传和下载图像?

谢谢。

回答

0

首先,您必须将您的所有图片设置为public在您的s3存储桶中。如果图像默认设置为私人。如果图像是私人的,你将无法看到图像。

其次,设置你的s3桶的所有凭证。

在**配置/ s3.yml文件集S3凭证作为

development: 
access_key_id: your_access_key_id 
secret_access_key: your_access_key 
bucket: your_bucket_name 
production: 
access_key_id: your_access_key_id 
secret_access_key: your_access_key 
bucket: your_bucket_name 

然后在配置/初始化/ s3.rb文件初始化所有图像作为

if Rails.env == "production" 
# set credentials from ENV hash 
S3_CREDENTIALS = { :access_key_id => ENV['access_key_id'], :secret_access_key => ENV['secret_key'], :bucket => "bucket_name"} 
else 
# get credentials from YML file 
S3_CREDENTIALS = Rails.root.join("config/s3.yml") 
end 
相关问题