I am using paperclip gem to upload files to S3, and also want to save the complete s3 filepath in image_file_name column in database.However only filename get stored.My model looks as below
class Product < ActiveRecord::Base
self.table_name = "catalog"
has_attached_file :image, :styles => { :medium => "300x300#", :thumb
=> "200x200#" }
attr_accessible :image_file_name,:image_cache
after_post_process :basename
private
def basename
self.image_file_name = @product.image.url(:medium)
end
Paperclip.interpolates :custom_filename do |attachment, style|
# Generate your desired file name here.
# The values returned should be able to be regenerated in the future because
# this will also be called to get the attachment path.
# For example, you can use a digest of the file name and updated_at field.
# File name and updated_at will remain the same as long as the file is not
# changed, so this is a safe choice.
self.image_file_name =
File.basename(URI.parse(attachment.original_filename).path)
end
end