Seems pretty simple, but I couldn't get it to work. Files work fine with S3 in a web application, but when I send them via email using the code below, the files are corrupted.
Application stack: rails 3, hero, clip + s3
Here is the code:
class UserMailer < ActionMailer::Base
if @comment.attachments.count > 0
@comment.attachments.each do |a|
require 'open-uri'
open("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}", "wb") do |file|
file << open(a.authenticated_url()).read
attachments[a.attachment_file_name] = File.read("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}")
end
end
end
mail( :to => "#{XXXX}",
:reply_to => "XXXXX>",
:subject => "XXXXXX"
)
a.authenticated_url () just gives me the url for s3 to get the file (of any type), I checked this works fine. Something related to the way I save tempfile should violate the ActionMailer application.
Any ideas?
source
share