Forum: Ruby on Rails Upload corrupts images. Any ideas why?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5b336f18b089138ec0968b2d9f12f03b?d=identicon&s=25 Sergei Serdyuk (sserdyuk)
on 2006-04-07 05:53
Hi,

I have written upload action and it seems to be working in general but
image files consistently get corrupted. They differ in both content and
size.
I have uploaded a small text file without any problems.

Everything is running on my laptop, WEBrick is the server.

Code:
***********
        begin
          @filename = @params['NewFile'].original_filename
          @filename.gsub!(/[^A-Za-z0-9._]/, '')
          File.open(@server_path + @filename, "w") { |f|
f.write(@params['NewFile'].read) }
        rescue
          @error_number = ERROR_NO_PERMISSIONS
        end
***********

Any ideas?

Sergei Serdyuk
Red Leaf Software LLC
http://www.redleafsoft.com
5b336f18b089138ec0968b2d9f12f03b?d=identicon&s=25 Sergei Serdyuk (sserdyuk)
on 2006-04-07 06:01
The answet was in the wiki already: need to use "wb" mode on Windows.

http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles
This topic is locked and can not be replied to.