I am getting Aws::S3::Errors::AccessDenied Access Denied whenever I tries to upload an image using paperclip and aws-sdk-s3.
I have almost tried all the solution available on Internet.
I have tried configuring paperclip default option from here
Gems used
gem "paperclip", git: "git://github.com/thoughtbot/paperclip.git" and gem 'aws-sdk-s3', '~> 1'
My development.rb file configuration looks like
config.paperclip_defaults = {
storage: :s3,
path: '/:class/:attachment/:id_partition/:style/:filename',
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['AWS_REGION'],
},
bucket: ENV['AWS_BUCKET'],
}
My model.rb file looks like
has_attached_file :photo
has_attached_file :image
has_attached_file :signature
My paperclip.rb file looks like
Paperclip::Attachment.default_options[:s3_protocol] = 'http'
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
My aws.yml file looks like
development:
access_key_id: MY_AWS_ACCESS_KEY_ID
secret_access_key: MY_AWS_SECRET_ACCESS_KEY
I am using gem 'figaro' to save my environment variable for development environment.
May if someone can assists me would be appreciated.
The reason for me getting Aws::S3::Errors::AccessDenied Access Denied was my canned ACL properties were not configured properly.
Thanks, It might help someone.
Related
I just set up an S3 bucket to upload my images and resources to and whenever I try to create a new book this error pops up. This is my first time using S3 so I am pretty confused. (I have my env all set up too - just didn't share for obvious reasons).
Any help would be greatly appreciated. Let me know if you need any more information.
application.rb - code:
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['AWS_REGION']
}
}
Error Message
The issue was that I had 'aws-sdk', '~> 2.0.0' in my gemfile instead of 'aws-sdk', '~> 2.6'.
Rais application deployed in aws elastic beantalk. Images are not loading from assets folder. I am trying to use s3 bucket to store assets. I got an error...
aws.yml
production:
access_key_id: 123333231331....
secret_access_key: 12212dddddd........
production.rb
config.paperclip_defaults = {
:storage => :s3,
:preserve_files => true,
:s3_credentials => 'aws.yml',
:s3_region => 'ap-south-1',
:s3_host_name => 's3.ap-south-1.amazonaws.com',
:bucket => 'xxxxxx'
}
I also give public access permissions in s3 bucket.
anyone: read write
gem...
gem 'aws-sdk', '~> 2.10', '>= 2.10.85'
aws.yml folder within config folder -- config/aws.yml
Have you tried using the path to the file, as at the bottom of your question: :s3_credentials => 'config/aws.yml'.
Otherwise, you might need to explicitly load the file from YAML and pass this in:
require 'yaml'
...
# again, perhaps using config/aws.yml, have a play
:s3_credentials => YAML.load_file('aws.yml')
...
Either of those help?
I am integrating paperclip with S3 bucket in RAILS 5. I am referring https://coderwall.com/p/vv1iwg/set-up-ruby-on-rails-with-paperclip-5-and-s3-using-aws-sdk-v2.
I have written the following in my development.rb:
config.paperclip_defaults = {
storage: :s3,
s3_region: 'us-west-2',
s3_credentials: {
bucket: 'mybucket',
access_key_id: 'my id',
secret_access_key: 'my secret key'
}
}
I am getting the below error while uploading image:
NameError (uninitialized constant Aws::VERSION):
I am using version 3.0.1 of gem aws-sdk
Instead of downgrading, you can introduce the variable that paperclip is missing in the current version. Adding this file works with aws-sdk 3.0.1 and paperclip 5.1.0, and will probably work until paperclip is updated to accommodate the aws changes.
# config/initializers/aws.rb
Aws::VERSION = Gem.loaded_specs["aws-sdk"].version
I have downgraded the aws-sdk version to aws-sdk (2.10.42) and it works.
Here is my config for CarrierWave with minimagick, I think something similar can be done for your case:
config/initializers/carrier_wave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['S3_ACCESS_KEY'],
aws_secret_access_key: ENV['S3_SECRET_KEY'],
region: ENV['S3_REGION']
}
config.fog_directory = ENV['S3_BUCKET']
end
Image Uploading was working fine, but when I tried switching it to S3, it started throwing an error. I get the following error when I try to create a new image upload:
cannot load such file -- aws-sdk (You may need to install the aws-sdk gem)
Relevant gems:
gem 'rails', '3.2.5'
gem 'paperclip'
gem 'aws-sdk'
config/s3.yml:
development:
bucket: bucketname
access_key_id: #
secret_access_key: #
test:
bucket: bucketname
access_key_id: #
secret_access_key: #
image_upload.rb:
has_attached_file :image,
:styles => {
:normal => "1680x6000",
:result => "560x3000",
:thumb => "140x500" },
:path => ":attachment/:style/:normalized_file_name.:extension",
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml"
Things I have tried:
bundle install
Change the version of aws-sdk to 1.3.4
gem install aws-sdk
Changed the s3_credentials "Rails.root" part to a few different things.
Thank you for the help!!
A little embarrassing... I just needed to restart rails server. Can't believe I forgot to do that.
What happens if you add require 'rubygems' to the top of the file where you are requiring aws-sdk?
I'm trying to fetch some files from my S3 bucket to my Rails 3 Application and stream them to the browser
In my Gemfile
gem 'aws-s3', :require => 'aws/s3'
and I also have configured my s3.yml
development:
bucket: my_unique_bucket
access_key_id: my_key
secret_access_key: my_super_key
test:
bucket: my_unique_bucket
access_key_id: my_key
secret_access_key: my_super_key
production:
bucket: my_unique_bucket
access_key_id: my_key
secret_access_key: my_super_key
Then in my controller I try to find the file inside the containing folder in the bucket
s3File = S3Object.find "My.pdf","PDFs"
but in the browser I get
AWS::S3::NoConnectionEstablished
Make sure you're establishing the connection to Amazon before your request.
Ex.
AWS::S3::Base.establish_connection!(
:access_key_id => 'ID',
:secret_access_key => 'KEY'
)