I'm relatively new to rails. I had the paperclip gem working fine in development locally with users uploading avatars on sign up with no problems. I deployed to production via Heroku and also had no errors when creating users with uploaded images on signup but all of the images that were uploaded appeared as missing thumbnails in production. I read up and apparently in production with paperclip I should use something called Amazon S3(correct me if there is a better way) so I'm trying to do that.
Here is the error I'm getting when I try to create a user with an uploaded image:
Aws::Errors::MissingRegionError in Devise::RegistrationsController#create
missing region; use :region option or export region name to ENV['AWS_REGION']
here is what I have in my production and development environments
config.paperclip_defaults = {
storage: :s3,
s3_host_name: 's3-ap-southeast-1.amazonaws.com',
s3_credentials: {
bucket: ENV['AWS_S3_BUCKET'],
s3_region: ENV['S3_REGION'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
}
Here is what I have in my paperclip.rb initializer
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 's3-ap-southeast-1.amazonaws.com'
note(I am in the middle east)
and here is what I have in my user model
#paperclip gem storing avatar images
has_attached_file :avatar,
:bucket => 'bucket_name',
:styles => {
:thumb => ['100x100#', :jpg, :quality => 70],
:preview => ['480x480#', :jpg, :quality => 70],
:large => ['600>', :jpg, :quality => 70],
:retina => ['1200>', :jpg, :quality => 30]
},
:convert_options => {
:thumb => '-set colorspace sRGB -strip',
:preview => '-set colorspace sRGB -strip',
:large => '-set colorspace sRGB -strip',
:retina => '-set colorspace sRGB -strip -sharpen 0x0.5'
}
I have looked for questions regarding S3 Paperclip Gem and missing Region error but have never seen one like this saying the error is in a Devise controller. I think it's because the association between the :avatar is with user which is controlled by devise and I don't have a separate users controller.
I feel like there should be an easier way to solve the problem of having missing images in production with paperclip gem than using this amazon S3 thing. Especially if everything was working fine and dandy locally without Amazon S3. Any alternative suggestions? Ideas?