I am trying to test aws s3 file upload functionality with the help of paperclip gem,I have installed fakes3 gem and ran fakes3 using
fakes3 -r ~/fakes3_root -p 4567;
I am getting Connection refused - connect(2) error while uploading file.
Here is my aws.yml file
development:
bucket: mybucket
access_key_id: abc
secret_access_key: pqr
s3_port: 4568
s3_host_name: localhost
s3_endpoint: localhost
sslEnabled: false
s3_force_path_style: true
Here is my model's part
as_attached_file :video,
:storage => :s3,
:path => ":attachment/:id/:style/:basename.:extension"
Please Help,
Thanks in advance
Related
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.
I'm using the configuration from this page: http://codesthq.com/blog/2015/gratuitious-development-with-aws-s3-and-paperclip.html
I can upload files to the local FakeS3 server, but when I generate a URL it returns a https:// link not https:// and I can't find a configuration option that changes it. I figure since the upload is working correctly, this is more likely a paperclip issue?
Here's my configuration:
config/initializers/aws.rb:
AWS::Rails.load_yaml_config
config/initializers/paperclip.rb:
paperclip_defaults = Rails.application.config_for :paperclip
paperclip_defaults.symbolize_keys!
Paperclip::Attachment.default_options.merge! paperclip_defaults
config/aws.yml:
development: &development
access_key_id: "abc"
secret_access_key: "abc"
s3_endpoint: "localhost"
s3_port: 10001
s3_force_path_style: true
use_ssl: false
test: *development
production: &production
access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
staging: *production
config/paperclip.yml:
development:
storage: :s3
bucket: "development"
s3_host_name: "localhost"
url: ":s3_alias_url"
s3_host_alias: "localhost:10001/development"
s3_protocol: 'http'
test:
storage: :s3
bucket: "test"
s3_host_name: "localhost"
url: ":s3_alias_url"
s3_host_alias: "localhost:10001/test"
s3_protocol: 'http'
production: &production
storage: :s3
bucket: <%= ENV["S3_BUCKET_NAME"] %>
url: ":s3_domain_url"
staging: *production
Versions installed:
$ bundle list | grep paperclip
* paperclip (4.3.6)
$ bundle list | grep aws
* aws-sdk (2.3.7)
* aws-sdk-core (2.3.7)
* aws-sdk-resources (2.3.7)
* aws-sdk-v1 (1.66.0)
Doh, I was over-riding s3_protocol in the model's attachment configuration!
I'm trying to build an app where users can upload a profile picture. I'm trying to use Paperclip and S3.
I've got it working on my local machine, but for some reason it doesn't work on Heroku. Specifically, nothing is getting uploaded to S3, but there are also no errors being produced in the Heroku logs from Paperclip or S3. Here's what I'm seeing in the logs:
2012-10-02T07:22:33+00:00 app[web.1]: [paperclip] Saving attachments.
2012-10-02T07:22:33+00:00 app[web.1]: [paperclip] saving profile_pictures/2/original.jpg
2012-10-02T07:22:33+00:00 app[web.1]: [paperclip] saving profile_pictures/2/thumb.jpg
2012-10-02T07:22:33+00:00 app[web.1]: [paperclip] saving profile_pictures/2/medium.jpg
2012-10-02T07:22:33+00:00 app[web.1]: [paperclip] saving profile_pictures/2/large.jpg
Here's what my s3.yml file looks like:
development:
access_key_id: XXXXXXX
secret_access_key: XXXXXXX
bucket: dev-bucket
test:
access_key_id: XXXXXXX
secret_access_key: XXXXXXX
bucket: test-bucket
production:
access_key_id: XXXXXXX
secret_access_key: XXXXXXX
bucket: prod-bucket
Anyone have an idea why this works on my dev machine but not on Heroku? I'm perplexed by the lack of an error...
Did you set the environment variables using Heroku Toolbelt?
$ heroku config:set AWS_BUCKET=**BUCKET NAME**
$ heroku config:set AWS_ACCESS_KEY_ID=***GET FROM AMAZON AWS***
$ heroku config:set AWS_SECRET_ACCESS_KEY=***GET FROM AMAZON AWS***
For this to work you would have to set:
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']
}
}
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'
)