【问题标题】:Image seems to be added to bucket, can't view it on my app图片似乎已添加到存储桶中,无法在我的应用上查看
【发布时间】:2013-06-01 18:00:46
【问题描述】:

我刚刚在 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 来显示要显示的图像。

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

谢谢。

【问题讨论】:

    标签: ruby-on-rails heroku amazon-s3 paperclip


    【解决方案1】:

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

    其次,设置您的 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
    

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 2022-12-05
      • 2011-03-01
      • 1970-01-01
      相关资源
      最近更新 更多