E
Eddy Velasquez
Hi everyone, I need some assistance, I'm trying to send a jpg file via
http post to a page in PHP, the file is sent in base64 encode, so the
page can convert it and save it to a directory in the server.
I have been able to acomplish this using Java and Python, but for some
reason I dont know, when I send via Ruby, the file is saved in the
server but its not a valid image file. I have tried the following
methods:
Method 1 (reading each char)
file64 = ''
File.open(filename,"rb") do |file|
file.each_char{|ch| file64+=ch }
end
encoded= [file64].pack('m')
Method 2 (reading the whole file and packing it)
encoded = [open(filename, "rb").read].pack('m')
Method 3 (reading the whole file and using Base64)
file64 = open(filename, "rb").read
encoded = Base64::encode64(file64)
Also, have tried to implement the script in this URL,
http://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#Ruby_version
but I got the same result that the others.
Am I missing something? Is there a special way to do this? There is
something I noticed, the lines of the encoded file, are 60 chars long,
and in python and java are 75 long.
Thanks in advance.
http post to a page in PHP, the file is sent in base64 encode, so the
page can convert it and save it to a directory in the server.
I have been able to acomplish this using Java and Python, but for some
reason I dont know, when I send via Ruby, the file is saved in the
server but its not a valid image file. I have tried the following
methods:
Method 1 (reading each char)
file64 = ''
File.open(filename,"rb") do |file|
file.each_char{|ch| file64+=ch }
end
encoded= [file64].pack('m')
Method 2 (reading the whole file and packing it)
encoded = [open(filename, "rb").read].pack('m')
Method 3 (reading the whole file and using Base64)
file64 = open(filename, "rb").read
encoded = Base64::encode64(file64)
Also, have tried to implement the script in this URL,
http://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#Ruby_version
but I got the same result that the others.
Am I missing something? Is there a special way to do this? There is
something I noticed, the lines of the encoded file, are 60 chars long,
and in python and java are 75 long.
Thanks in advance.