I'm using Rails 4, Ruby 2.0, Paperclip 3.5.2. My production.rb has the following
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
I can save files and I can retrieve the files in the view.html.erb with
`<%= image_tag card.ai.url(:thumb) %>`
My question is, how can I access the file in the controller? I would like to add it to a zip file, z:
def create_zip
....
elsif ENV['RAILS_ENV'] == "production"
z.add_file(card.ai.path)
...
end
This gives the error: "Can't open file: No such file or directory". Also tried "card.ai.url.path"- of course that didn't work. I've read [Paperclip + S3 massive zipping, but no I don't want to disable anything. So basically there's a lot of posts that say how to show the image file in the .html.erb file, but I want to access it in the controller.
-so close to finishing
Have gotten this far...it doesn't crash the website and temp_file does go into the zip file, but temp_file is empty.
s3One = AWS::S3.new(:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])
cardsets_bucket = s3One.buckets[ENV['S3_BUCKET_NAME']]
ai_file_object = cardsets_bucket.objects[card.ai]
temp_dir_name = "#{Rails.root}/public/temp/pictures}"
temp_dir = File.dirname("#{temp_dir_name}")
unless File.directory?("#{temp_dir_name}")
FileUtils.mkdir_p("#{temp_dir_name}")
end
if File.exists?("#{temp_dir_name}/tempPicture.jpg")
File.delete("#{temp_dir_name}/tempPicture.jpg")
end
temp_file = File.new("#{temp_dir_name}/tempPicture.jpg", 'w')
File.open("#{temp_dir_name}/tempPicture.jpg", 'w') do |file|
ai_file_object.read do |chunk|
file.write(chunk)
end
end
z.add_file("#{temp_dir_name}/tempPicture.jpg")
Have also tried ai_file_object = cardsets_bucket.objects[card.ai.url] --still tempPicture is empty. Also tried card.ai.path and results in error AWS can not find key.
Thanks in advance.