I am using carrierwave and fog-aws while uploading a file to aws and storing the aws url in my local DB table.I have created carrierwave.rb
file to config all fog-aws credentials.
begin
CarrierWave.configure do |config| # required
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'Key_id', # required
:aws_secret_access_key => 'access_key', # required
:region => 'us-west-2' # o\tional, defaults to 'us-east-1'
# :fog => 'host',
# :endpoint => 'host'
}
config.fog_directory = 'my-images-server' # required
# see https://github.com/jnicklas/carrierwave#using-amazon-s3
# for more optional configuration
config.fog_public = true # optional, defaults to true
My uploader file contains
class QueryUploader < CarrierWave::Uploader::Base
storage :fog
def store_dir
base_dir = File.join(Rails.root, "public", "uploads")
"#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"/tmp/service-quep"
end
def extension_white_list
%w(sql)
end
end
I read many articles and breaking my head from 2days, still could not find any solution.My access key is without space and bucket name is not trailing with a slash.Can anyone please tell why this
Expected(200) <=> Actual(403 Forbidden) excon.error.response :body => "\n
SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your key and signing method.YTUUYUDTDYJBKJNUFYD
error is coming.
Look, on this method you don't need to write extra code because of Rails directory mapping automatically like if you use "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
then it automatically mapping /public/uploads/...
your code
def store_dir
base_dir = File.join(Rails.root, "public", "uploads")
"#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
it will be
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
You can check this gist
this is great for working with Rails, CarrierWave and AWS, also you can check this