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!
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 am running the command rail s and it displays the following error:
/home/user/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/settingslogic-2.0.9/lib/settingslogic.rb:189:in `missing_key': Missing setting 'mail_from' in /home/user/myapp/my_app/config/application.yml (Settingslogic::MissingSetting)
what is wrong in application.yml?
my config/application.yml
defaults: &defaults
site_name: site
host: site
url: site
resque:
server: 127.0.0.1:6379
namespace: resque_namespace
smtp:
domain: domain
login: login
password: secret
server: host
port: 25
mail_from: mail#example.com
robokassa:
login: login
test_mode: false
pass1: secret
pass2: secret
token: secret
avisosms:
login: login
service_id: 666
hash: secret
sdpays:
md5: secret
project_id: 666
edit_delay: 5
contest_id: 1
aws:
ses:
access_key_id: secret
secret_access_key: secret
s3:
access_key_id: secret
secret_access_key: secret
bucket: bucket
fog_directory: dir
s3cmd: /usr/bin/s3cmd
vk:
key: key
secret: secret
recaptcha:
public_key: key
private_key: private_key
development:
#<<: *defaults
host: 'localhost:3666'
url: 'http://localhost:3666'
resque:
server: '127.0.0.1:6379'
namespace: 'bdsmg_development_resque'
aws:
ses:
access_key_id: key
secret_access_key: secret
s3:
access_key_id: key
secret_access_key: secret
bucket: bucket
fog_directory: dir
s3cmd: /usr/local/bin/s3cmd
staging:
<<: *defaults
test_email: mail#example.com
host: host
url: http://host
test:
<<: *defaults
production:
<<: *defaults
Any help will be appreciated.
This seems to be some indentation issue. The mail_from field needs to be inside the smtp block.
smtp:
domain: domain
login: login
password: secret
server: host
port: 25
mail_from: mail#example.com
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
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'
)
I'm using paperclip which has a /config/s3.yml file with the following:
common: &common
access_key_id: XXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXX
development:
<<: *common
bucket: myapp-local-dev
test:
<<: *common
bucket: myapp-123-test
production:
<<: *common
bucket: myappname-313-production
In my view I would like to dynamically be able to do something like this:
<img src="http://s3.amazonaws.com/myapp-local-dev/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
or
<img src="http://s3.amazonaws.com/myappname-313-production/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
Somehow, knowing the current environment and then getting the bucket name. Possible? thanks
YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env]["bucket"]
Should do the trick if you just want to return the bucket name.
If you're using Paperclip with aws/s3 this should be handled automatically though.
So:
<%= image_tag #my_obj.image.url %>
should return the desired url regardless of the environment
Hope that helps?