I'm having trouble with heroku and papaerclip. I'm not sure what I'm doing wrong. Pretty confused since it worked perfectly in development, the issue comes up when I push it to heroku because as soon as I try to upload the image, I get this error.
Heroku Log:
2015-05-18T00:15:34.061408+00:00 app[web.1]: Command :: file -b --mime '/tmp/08ca2a4172b01652a903ac7ea654dd8420150518-3-1rzcdt7.JPG'
2015-05-18T00:15:34.141479+00:00 app[web.1]: [paperclip] saving /products/images/000/000/026/original/9780132413770_p0_v1_s260x420.JPG
2015-05-18T00:15:34.496353+00:00 app[web.1]: (8.5ms) ROLLBACK
2015-05-18T00:15:34.501384+00:00 app[web.1]:
2015-05-18T00:15:34.501387+00:00 app[web.1]: ArgumentError (missing required :bucket option):
2015-05-18T00:15:34.501389+00:00 app[web.1]: app/controllers/products_controller.rb:32:in `create'
2015-05-18T00:15:34.501390+00:00 app[web.1]:
2015-05-18T00:15:34.501391+00:00 app[web.1]:
2015-05-18T00:15:34.499623+00:00 app[web.1]: Completed 500 Internal Server Error in 1672ms
2015-05-18T00:15:34.506211+00:00 heroku[router]: at=info method=POST path="/products" host=x.herokuapp.com request_id=4c535aa6-0646-43dc-a09b-89da53300543 fwd="173.88.52.151" dyno=web.1 connect=1ms service=1698ms status=500 bytes=1754
2015-05-18T00:15:34.981329+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=x.herokuapp.com request_id=881783da-7e06-45a7-a306-c09d62dcec5b fwd="173.88.52.151" dyno=web.1 connect=1ms service=9ms status=304 bytes=133
products_controller.rb
def create
@product = current_user.products.new(product_params)
@product.save
respond_with(@product)
end
models/Product.rb
class Product < ActiveRecord::Base
validates_presence_of :title, :image
has_attached_file :image, styles: {large: "600x600", medium: "300x300", thumb: "150x150"}
validates_attachment_content_type :image,
content_type: /^image\/(png|gif|jpeg)/,
message: "Only images allowed"
validates :image, attachment_presence: true
end
initializers/paperclip.rb
Paperclip::Attachment.default_options.merge!({
storage: :s3,
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['AWS_BUCKET']
},
url: ":s3_domain_url",
path: "/:class/:attachment/:id_partition/:style/:filename"
})
config/environments/development.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_protocol => 'http',
:bucket => ENV['AWS_BUCKET'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
config/environments/production.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_protocol => 'http',
:bucket => ENV['AWS_BUCKET'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
.env file
export AWS_BUCKET=xxx
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxx
Aucun commentaire:
Enregistrer un commentaire