Forum: Ruby on Rails Email attachment

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Markus (Guest)
on 2007-01-07 22:11
I'm quite new to Ruby and Rails. Now I'm stuck on a problem with
receiving emails. Everything but attachments work just fine. I try to
save the attached file (jpeg) in a file.

I use a Windows XP system and use Outlook to send the mails.

My receive function looks like this:
class Receiver < ActionMailer::Base
def receive(email)
  Post.create(:title => email.subject, :body => email.body, :created_at
=> do |part|
    filename = "#{RAILS_ROOT}/public/post/image/test.jpg",File::CREAT|File::TRUNC|File::WRONLY,0644){ |f|

The problem is that the saved file is not an exact copy of the original
file. I see the pattern below:
Original:  .. 07 08 09 0A 0B FF ..
Saved:     .. 07 08 09 0D 0A 0B FF ..
(All 0A are replaced with 0D 0A)

So, there is a problem with "line feeds" in the image data. But what and
why? What can I do about it?
Markus (Guest)
on 2007-01-08 18:49
Problem solved. Need a "file.binmode"
This topic is locked and can not be replied to.