Paperclip CloudFiles? - ruby-on-rails

How can I use Paperclip with CloudFiles? I found paperclip-cloudfiles, but in the description it says it will probably be removed and the last commit was in 2010.

Gemfile:
gem 'fog'
config/environments/production.rb
Paperclip::Attachment.default_options.update({
:path => ":picturable_name/:basename_:style.:extension",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => RACKSPACE_USERNAME,
:rackspace_api_key => RACKSPACE_API_KEY,
:persistent => false
},
:fog_directory => CONTAINER_NAME,
:fog_public => true
})

Related

Upload image using paperclip, fog and rackspace

I need to upload an logo image to rackspace using fog & paperclip.
Paperclip::Attachment.default_options.update({
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => 'blablabla',
:rackspace_api_key => 'blablabla',
:persistent => false
},
:fog_directory => 'blablabla',
:fog_public => true,
:fog_host => 'http://blablabla.rackcdn.com'
})
I have this settings in config/initializers/paperclip_defaults.rb
But how to initialize the logo to catch those settings. Please help me i was in a confusion here.
You don't need to initialize the logo to "catch" those settings
Let me explain how it works:
Paperclip simply creates an entry into your db, and stores your file on Rackspace. Accessing the file, with paperclip will simply be a case of ensuring paperclip is able to load the RackSpace URL correctly
I would do this:
#config/application.rb
config.paperclip_defaults = {
styles: { :medium => "x500", :thumb => "x200" },
default_url: "placeholder.png"
}
#config/environments/production.rb
Paperclip::Attachment.default_options.merge!({
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => 'blablabla',
:rackspace_api_key => 'blablabla',
:persistent => false
},
:fog_directory => 'blablabla',
:fog_public => true,
:fog_host => 'http://blablabla.rackcdn.com'
})
This allows you to upload to Rackspace in production mode. You don't need to change the model, and would call your paperclip objects like this:
#model.image.url #-> yields rackspace URL
If you need more help / clarity, please let me know. I have just used your Rackspace code & moved from an initializer to your config files

trouble with dots using rails paperclipftp

I got trouble with paperclipftp
Here my config :
has_attached_file :resume_img, :styles => { :thumb => "100x100#",:screen => '690x780#' },:retina => { :quality => 70 },
:path => "username.com/uploads/:attachment/:id/:style/:filename",
:url => "http://username.com/:attachment/:id/:style/:filename",
:storage => :ftp,
:ftp_credentials => { :host => 'ftp.username.com', :username => 'username', :password => '*******' },
:ftp_passive_mode => false,
:ftp_timeout => 90,
:ftp_verify_size_on_upload => false,
:ftp_debug_mode => false
My FTP is hosted by dreamhost, I need to upload inside the folder username.com but something strange appears rails escape the dots so it upload to usernamecom/uploads/
It does the same with the url it try to find the image at http://usernamecom/
Any idea???
Try it maybe escaped with
"username\.com/uploads/:attachment/:id/:style/:filename"

Rails download S3 file

I'm uploading files to S3 with paperclip, and now I would like to download them from the same app. So I'm doing what lots of pages says, but if I use 'aws-sdk' it says that AWS::S3::S3Object method 'find' doesn't exist, and If I use 'aws-s3' gem, it says that I need to use 'aws-sdk'.
In controller I'm calling:
aws_object = AWS::S3::S3Object.find #component.folder.path, 'bucket-name'
send_data(aws_object.value, :type => #component.folder_content_type)
EDIT:
My model looks like:
attr_accessible :folder
has_attached_file :folder,
:path => ":rails_root/data/folders/:id/:basename.:extension",
:storage => :s3,
:s3_credentials => {
:bucket => "my-bucket-name",
:access_key_id => "XXXXXXXXX",
:secret_access_key => "XXXXXXXXX"
}
This worked for me:
http://trevorturk.com/2008/12/11/easy-upload-via-url-with-paperclip/
There's a example to download too.
The secret was ".read" :
data = open(asset.uploaded_file.url)
send_data data.read, :type => data.content_type, :x_sendfile => true,:filename => asset.file_name

Heroku Paperclip S3 error => AWS::S3::Errors::SignatureDoesNotMatch

Paperclip+S3 work on the local machine but dont work on Heroku. It says "AWS::S3::Errors::SignatureDoesNotMatch"
2012-04-20T21:24:37+00:00 app[web.1]: Parameters: {"utf8"=>"Γ£ô",
"authenticit y_token"=>"MHt20N64y9L24Ga2y6gGj8hX06U+td17XIRdqMadcCQ=",
"post"=>{"title"=>"tes t", "organisation_id"=>"1", "content"=>"weeqw",
"attachments_attributes"=>{"0"=>
{"pic"=>#>}}},
"commit"=>"Create Post"} 2012-04-20T21:24:41+00:00 app[web.1]:
Completed 500 Internal Server Error in 344 6ms
2012-04-20T21:24:41+00:00 app[web.1]: 2012-04-20T21:24:41+00:00
app[web.1]: AWS::S3::Errors::SignatureDoesNotMatch (Th e request
signature we calculated does not match the signature you provided. Che
ck your key and signing method.):
Here is my attachment.rb model:
has_attached_file :pic, :styles => { :medium => "500x280>",:slide => "180x260>", :thumb => "150x100#" },
:storage => :s3,
:bucket => 'sample_bucket',
:s3_credentials => {
:access_key_id => 'ASDDSAMPLEKEYDFSDF',
:secret_access_key => 'Dfsdf887-sample-secret-key-dfdsasd',
}
What might be the reason of this error?
I've paperclip 2.4.5 and here is the definition inside the model:
has_attached_file :logo,
:path => "assets/:class/:attachment/:id/:style.:extension",
:storage => :s3,
:bucket => ENV['S3_BUCKET'],
:s3_permissions => 'authenticated-read',
:s3_protocol => "http",
:s3_credentials => { :access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET'] },
:styles => { :index => "72x72>",
:billboard => "120x120>" }
I was having some similar issues with Heroku and found this https://rubygems.org/gems/paperclip-aws.
This solved my problem.

heroku+s3+paperclip

Guys,
I'm having a problem with s3...I'm trying to configure the s3 this way to work with the paperclip:
has_attached_file :photo,
:storage => :s3,
:bucket => 'gallerybucket',
:styles => { :small => ["150", :png], :large => ["500", :png], :very_large => ['750x500>', :png] },
:path => ":rails_root/public/images/:class/:attachment/:id/:style_:basename.png",
:url => "/images/:class/:attachment/:id/:style_:basename.png",
:default_url => "/images/sem_imagem.gif",
:s3_credentials => {
:access_key_id => ENV['ac'],
:secret_access_key => ENV['sc']
}
but it always shows me this error. I don't understand what I'm doing wrong here. Is there some configuration missing?
If you don't have an s3 account already go get one here:
http://aws.amazon.com/s3/
You need to add this to your contact model:
app/models/contact.rb
has_attached_file :picture,
:styles => {:large => "275x450>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "appname/:attachment/:style/:id.:extension"
Make sure you appname is your rails app name on heroku. And make sure you rename picture to whatever you have named your picture.
Then you need a config file in config/s3.yml.
development:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
production:
bucket: bucked_name
access_key_id: key
secret_access_key: secret
Make sure you get the key and secret correct.
In your gem file make sure you have these gems install :
gem "aws-s3", :require => "aws/s3"
gem "paperclip"
Sounds like you added the variables to you heroku account, but did you add them to your .bashrc file?
export ACCESS_KEY_ID='acckeyid'
export SECRET_ACCESS_KEY='secacckey'
Then in your code:
:s3_credentials => {
:access_key_id => ENV['ACCESS_KEY_ID'],
:secret_access_key => ENV['SECRET_ACCESS_KEY']
}
I have a blog post I wrote that talks about this a little as well.

Resources