我正在尝试使用回形针将发送到我的 rails 应用程序的图像附件保存到 s3,但是我遇到了这些问题:
它进入附件循环并失败
NoMethodError (undefined method `size' for #<Mail::Part:
0x2b62856e8030>):
app/mailers/user_mailer.rb:23:in `receive'
app/mailers/user_mailer.rb:14:in `each'
app/mailers/user_mailer.rb:14:in `receive'
app/controllers/emails_controller.rb:10:in `create'
这是线
:photo_file_size => attachment.size,
注释掉那一行,我在尝试创建时遇到了这个错误:
NoMethodError (undefined method `to_tempfile' for #<Mail::Part:
0x2ac5eb944220>):
下面是我的代码。感谢帮助..
class UserMailer < ActionMailer::Base
def receive(email)
@user = User.find_or_create_by_email(
#:name => FIXME,
:email => email.from,
:password => 'password',
:password_confirmation => 'password'
)
@item = Item.create(:title => email.subject, :user => @user, :price => 50)
if email.has_attachments?
for attachment in email.attachments
@item.photos.create(
:photo => attachment,
:photo_file_name => attachment.original_filename,
:photo_content_type => attachment.content_type,
:photo_file_size => attachment.size,
:photo_updated_at => Time.now.to_datetime)
@item.photos << attachment
end
end
end
end
对我的附件对象进行检查给了我这个:
#<Mail::Part:23597877753640, Multipart: false, Headers: <Date: Wed, 25 Aug 2010 16:55:07 -0700>, <Mime-Version: 1.0>, <Content-Type: image/JPG; name="photo.jpeg">, <Content-Transfer-Encoding: base64>, <Content-Disposition: inline; filename=photo.jpeg>, <Content-ID: <4c75ad5b3cbed_52fe15764b0bf938695a@railgun64.30856.mail>>>