Rails Paperclip S3 ArgumentError (missing required :bucket option):

后端 未结 1 595
庸人自扰
庸人自扰 2021-01-15 04:03

I\'ve been stuck on this for ages now and can\'t figure out what\'s wrong. There are a lot of people that seem to have this same problem, but I can\'t actually find any answ

相关标签:
1条回答
  • 2021-01-15 04:59

    Here is my paperclip initialization stuff:

    Paperclip::Attachment.default_options.merge!({
        storage: :s3,
        s3_credentials: {
            access_key_id: ENV['S3_KEY'],
            secret_access_key: ENV['S3_SECRET'],
            bucket: "#{ENV['S3_BUCKET']}-#{Rails.env}"
            },
        url: ":s3_domain_url",
        path: "/:class/:attachment/:id_partition/:style/:filename"
        })
    

    This assumes that we have three environment variables setup called, you guessed it... S3_KEY, S3_SECRET, and S3_BUCKET. I did a little trick so that I could have a different bucket in each environment by adding Rails.env to the bucket variable.

    You seem to indicate in your question that you're putting the actual name of the bucket in the reference to ENV, which would not work. You should put the name of the bucket in the environment variable and use the name of the environment variable as the key.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题