Hi, I''m using the below method to copy/upload a file. The outcome is an image with the proper dimensions but looks garbled and pixelated. I''m baffled as to what''s going on. What''s even weirder is this same function with the same image works for my colleague. He is using OS/10 and I am using Windows Media Center. Any ideas? # # destination is the pathname of the target # file is the source file # 1 def upload_file(file, destination) 2 File.open(destination, "w") { |f| f.write(file.read) } 3 end -- Posted via http://www.ruby-forum.com/.
I believe that you need under windows to specify that it is a binary file; that''s been my experience with other programming languages (C and the like) -- Unixen treat files as binary by default and windows as text by default. Given that the same code works on OSX and not on windows, I believe that is the culprit. Hope that helps, Matt On Thu, 1 Jun 2006, Joe Cairns wrote:> Hi, I''m using the below method to copy/upload a file. The outcome is an > image with the proper dimensions but looks garbled and pixelated. I''m > baffled as to what''s going on. > > What''s even weirder is this same function with the same image works for > my colleague. He is using OS/10 and I am using Windows Media Center. > > Any ideas? > > # > # destination is the pathname of the target > # file is the source file > # > 1 def upload_file(file, destination) > 2 File.open(destination, "w") { |f| f.write(file.read) } > 3 end > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Matthew Williams wrote:> I believe that you need under windows to specify that it is a binary > file; > that''s been my experience with other programming languages (C and the > like) -- Unixen treat files as binary by default and windows as text by > default. Given that the same code works on OSX and not on windows, I > believe that is the culprit. > > Hope that helps, > MattHey thanks for the suggestion, how would I specify that file to a binary in Ruby? I found that the before and after file sizes are slightly different: before: 71,027 bytes after: 71,287 bytes -- Posted via http://www.ruby-forum.com/.
Matthew Williams wrote:> I believe that you need under windows to specify that it is a binary > file; > that''s been my experience with other programming languages (C and the > like) -- Unixen treat files as binary by default and windows as text by > default. Given that the same code works on OSX and not on windows, I > believe that is the culprit. > > Hope that helps, > MattFound it, thanks that''s exactly what it is! Changed my filewriter and now all is well! File.open(destination, "wb") { |f| f.write(file.read) } -- Posted via http://www.ruby-forum.com/.