【发布时间】:2011-01-10 23:08:34
【问题描述】:
看起来很简单,但我无法让它工作。这些文件在网络应用程序上的 S3 工作正常,但是当我通过下面的代码将它们通过电子邮件发送出去时,文件已损坏。
应用堆栈:rails 3、heroku、回形针 + s3
代码如下:
class UserMailer < ActionMailer::Base
# Add Attachments if any
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() 只是给了我一个 s3 的 URL 来获取文件(任何类型),我检查了这个,工作正常。与我保存临时文件的方式有关的事情一定是破坏了 ActionMailer 附件。
有什么想法吗?
【问题讨论】:
-
你能确认从S3下载的tmp文件没问题吗?
标签: ruby-on-rails ruby-on-rails-3