Hi, I use a web service for delivering snailmail. I prepare a zip-file containing pdf for the letter, receivers and so on, encode it in base64 and send it as base 64 in my request. It won''t work in 1.9.2 (the zip gets corrupted) but works fine in 1.8.7. I guess it''s something with how binary strings are handled. This is the code that works in 1.8.7: file_data = File.open(temp_file.path,"rb") {|io| io.read} file_data_64 = Base64.encode64(file_data) Does anyone know how to do this in 1.9.2? Thanks jonas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 10, 7:51 am, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote:> Hi, > > I use a web service for delivering snailmail. I prepare a zip-file > containing pdf for the letter, receivers and so on, encode it in > base64 and send it as base 64 in my request. It won''t work in 1.9.2 > (the zip gets corrupted) but works fine in 1.8.7. I guess it''s > something with how binary strings are handled. This is the code that > works in 1.8.7: > > file_data = File.open(temp_file.path,"rb") {|io| io.read} > file_data_64 = Base64.encode64(file_data) > > Does anyone know how to do this in 1.9.2? >require "base64" content = File.binread("filename") encoded = Base64.encode64(content) There you go. -- Luis Lavena -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
That worked well in 1.8.7, but not in 1.9.2. On 10 Nov, 14:59, Luis Lavena <luislav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 10, 7:51 am, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote: > > > Hi, > > > I use a web service for delivering snailmail. I prepare a zip-file > > containing pdf for the letter, receivers and so on, encode it in > > base64 and send it as base 64 in my request. It won''t work in 1.9.2 > > (the zip gets corrupted) but works fine in 1.8.7. I guess it''s > > something with how binary strings are handled. This is the code that > > works in 1.8.7: > > > file_data = File.open(temp_file.path,"rb") {|io| io.read} > > file_data_64 = Base64.encode64(file_data) > > > Does anyone know how to do this in 1.9.2? > > require "base64" > > content = File.binread("filename") > encoded = Base64.encode64(content) > > There you go. > > -- > Luis Lavena-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The next thing I do is: response = client.request :sendWithAddressing, :body => { :in0 => file_data_64, :in1 => ''ebrevwebb'', :in2 => ''jebkb'', :in3 => ''ebrevwebb'' } With exactly the same ruby code the encoded file in the request starts the same but then there are diffrences. The length of the encoded file in the request is 4803 chars in 1.8.7 and 4864 chars in 1.9.2. The receiving end does not accept the request from 1.9.2 saying it''s an illegal zip. On 10 Nov, 18:23, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote:> That worked well in 1.8.7, but not in 1.9.2. > > On 10 Nov, 14:59, Luis Lavena <luislav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > On Nov 10, 7:51 am, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote: > > > > Hi, > > > > I use a web service for delivering snailmail. I prepare a zip-file > > > containing pdf for the letter, receivers and so on, encode it in > > > base64 and send it as base 64 in my request. It won''t work in 1.9.2 > > > (the zip gets corrupted) but works fine in 1.8.7. I guess it''s > > > something with how binary strings are handled. This is the code that > > > works in 1.8.7: > > > > file_data = File.open(temp_file.path,"rb") {|io| io.read} > > > file_data_64 = Base64.encode64(file_data) > > > > Does anyone know how to do this in 1.9.2? > > > require "base64" > > > content = File.binread("filename") > > encoded = Base64.encode64(content) > > > There you go. > > > -- > > Luis Lavena-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 10, 2:23 pm, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote:> That worked well in 1.8.7, but not in 1.9.2. >Dunno what are you doing, but works fine for me: C:\Users\Luis>ruby -v ruby 1.9.2p290 (2011-07-09) [i386-mingw32] C:\Users\Luis>irb irb(main):001:0> require "base64" => true irb(main):002:0> content = File.binread(".TransferManager.db"); nil => nil irb(main):003:0> content.length => 15388 irb(main):004:0> encoded = Base64.encode64(content); nil => nil irb(main):005:0> encoded.length => 20862 The ''nil'' at the end is to avoid the entire binary file output in this example. PS: there is no "File.binread" in Ruby 1.8.7, so dunno how that worked. -- Luis Lavena -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Well, the binread works fine for me. I tried to create a file from the encoded data and that looks fine, so the problem is something else. I wonder if # encoding: utf-8 first in the file can mess things up. On 10 Nov, 18:45, Luis Lavena <luislav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 10, 2:23 pm, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote: > > > That worked well in 1.8.7, but not in 1.9.2. > > Dunno what are you doing, but works fine for me: > > C:\Users\Luis>ruby -v > ruby 1.9.2p290 (2011-07-09) [i386-mingw32] > > C:\Users\Luis>irb > irb(main):001:0> require "base64" > => true > irb(main):002:0> content = File.binread(".TransferManager.db"); nil > => nil > irb(main):003:0> content.length > => 15388 > irb(main):004:0> encoded = Base64.encode64(content); nil > => nil > irb(main):005:0> encoded.length > => 20862 > > The ''nil'' at the end is to avoid the entire binary file output in this > example. > > PS: there is no "File.binread" in Ruby 1.8.7, so dunno how that > worked. > > -- > Luis Lavena-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.