你没有设置一个桶。它位于您的 s3.yml 文件中,但您没有从调用中读取该值has_attached_file
.
回形针 S3 文档:http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3#s3_protocol-instance_method http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3#s3_protocol-instance_method
另外,请注意那些告诉您不要在 Heroku 中使用 s3.yml 文件的人。这是一种浪费,而且只是增加了抽象,对你没有任何好处。您已经使用所需的值设置了 ENV,因此请使用它们。
我之前已经这样做过,我不想将 s3.yml 文件推送到 Heroku,但我确实想使用一个进行测试和开发。在初始化程序中,您可以执行以下操作:
# If an s3.yml file exists, use the key, secret key, and bucket values from there.
# Otherwise, pull them from the environment.
if File.exists?("#{Rails.root}/config/s3.yml")
s3_config = YAML.load_file("#{Rails.root}/config/s3.yml")
S3[:key] = s3_config[Rails.env]['key']
S3[:secret] = s3_config[Rails.env]['secret']
S3[:bucket] = s3_config[Rails.env]['bucket']
else
S3[:key] = ENV['S3_KEY']
S3[:secret] = ENV['S3_SECRET']
S3[:bucket] = ENV['S3_BUCKET']
end
然后,当您在模型中设置 Paperclip 时,您可以像这样引用该值:
...
:s3_credentials => {
:access_key_id => S3[:key],
:secret_access_key => S3[:secret]
},
:bucket => S3[:bucket]
显然,这意味着您不希望将 s3.yml 文件放在 git 存储库中(实际上,无论如何您都不应该这样做)。