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获取要显示的图像。

我没有在任何地方为图像设置权限。它们是否会自动为应用程序正确设置以上传和下载图像?

谢谢。

4

1 回答 1

0

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

其次,设置您的 s3 存储桶的所有凭据。

在 **config/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

然后在config/initializers/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
于 2013-06-05T09:58:38.770 回答