Rails Excon :: Errors :: Forbidden - Expected(200)< =>实际(403禁止)

时间:2016-03-21 19:16:21

标签: ruby-on-rails amazon-s3 carrierwave fog

我在我的本地环境中,我正在使用载波和雾两个上传图像和文件分离上传者。

我在我的本地电脑上,我将使用DigitalOcean而不是Heroku

在我的附件上传器中,我只有:

class AttachmentUploader < CarrierWave::Uploader::Base

 storage :fog

   def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
   end
end

Gemfile:

gem 'carrierwave', '~> 0.10.0'
gem 'mini_magick', '~> 4.3.6'
gem 'fog', '~> 1.36.0'

配置/初始值设定/ carrierwave.rb

CarrierWave.configure do |config|
 config.fog_credentials = {
    :provider => 'AWS',
    :aws_access_key_id => ENV['S3_ACCESS_KEY'],
    :aws_secret_access_key => ENV['S3_SECRET_KEY']
 }
 config.fog_directory = ENV['S3_BUCKET']
end

application.yml(使用figaro创建)

development:
DEV_DB_NAME: archgard_cms_development
DEV_DB_USERNAME: username
DEV_DB_PASSWORD: password
S3_ACCESS_KEY: AKIAJXAY2SZYZYYOH7HA
S3_SECRET_KEY: QAZTM/qYjl/bimDLSiWD7DqvbcyaW38yGTY+4lOSjtEav
S3_BUCKET: various-bucket

test:
TEST_DB_NAME: archgard_cms_test
TEST_DB_USERNAME: username
TEST_DB_PASSWORD: password

production:
PRO_DB_NAME: archgard_cms_production
PRO_DB_USERNAME: username
PRO_DB_PASSWORD: password
PRO_DEVISE_SECRET_KEY: 37f2b350d33b55c6a3b428558da7a48d2f24462d88d90b9b6275ceadcb92ec15ae56a50a0dda06dfa6b564dc489f26a30dd3bdjskjskjsdunnnieujeje
S3_ACCESS_KEY: AKIAJXAY2SZYZYYOH7HA
S3_SECRET_KEY: QAZTM/qYjl/bimDLSiWD7DqvbcyaW38yGTY+4lOSjtEav
S3_BUCKET: various-bucket

Amazon S3存储桶策略:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Action": [
            "s3:ListAllMyBuckets"
        ],
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::*"
    },
    {
        "Action": "s3:*",
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::various-bucket"
    },
    {
        "Action": "s3:*",
        "Effect": "Allow",
        "Resource": "arn:aws:s3:::various-bucket/*"
    }
]
}

我在亚马逊创建了名为:carlos21的用户,我也添加了AmazonS3FullAccess和AdministratorAccess。创建用户后,我创建了存储桶。

我甚至尝试使用亚马逊的superadmin凭证。

1 个答案:

答案 0 :(得分:1)

我解决了。

问题在于:

在我的本地环境中,我在barh配置文件中拥有密钥和秘密。当我尝试上传图像时,应用程序变量正在响应该文件。

我刚刚删除了这些行,并使用了application.yml

中的行