I’m creating a Ruby client for some web service and need to send a file
to that service. Since I’m a newbie, I have problems translating this
Java code into Ruby:
On Apr 2, 2007, at 5:41 AM, Marko Marjanovic wrote:
Rob B. wrote:
On Mar 30, 2007, at 8:02 AM, mare wrote:
You’re close, try this:
content = Base64.encode64(File.read(filePath))
tried, but the results from Java and this code do not match… Any
ideas
why?
If you’re on Windoze, perhaps:
f = File.open(filePath, ‘rb’)
encoded = f.read
f.close
content = Base64.encode64(encoded)
Or take the Base64 out of the picture and make sure that you get the
same result on a plain file. If you have a difference in the length
of the output by 4/3 of the number of lines in the original, it’s
very likely a line ending difference.
Other than that, no one is going to be able to help without more
information. Perhaps create a small file and post the result if you
can’t figure it out from there.
If you’re on Windoze, perhaps:
f = File.open(filePath, ‘rb’)
encoded = f.read
f.close
content = Base64.encode64(encoded)
I tried the code you suggested and compared the results with the Java’s
output. The following happened:
Performed on a small csv file, both Java and Ruby gave the same
output (the file was cp1252 encoded with \r\n line endings).
Performed on the same file saved as xls (Excel) spreadsheet, Java
gave cp1252 encoded output with \r\n line endings and Ruby gave utf-8
encoded output with \n line endings.
I read these attributes from JEdit. Both Java and Ruby codes were saved
and run from Eclipse.
Any ideas how it could be fixed? Should I provide more (and what)
information?