# Need help posting a base64-encoded binary via xml-rpc

**URL:** <https://www.ruby-forum.com/t/need-help-posting-a-base64-encoded-binary-via-xml-rpc/108032>\
**Category:** Ruby\
**Created:** [June 28, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/need-help-posting-a-base64-encoded-binary-via-xml-rpc/108032 "2007-06-28T16:11:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phildog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/db5fbb/32.png) [@phildog](https://www.ruby-forum.com/u/phildog)\
**Post date:** [June 28, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/need-help-posting-a-base64-encoded-binary-via-xml-rpc/108032/1 "2007-06-28T16:11:38Z")

</div>

Hi folks. I’m trying to post a base64-encoded binary (an mp3 file) via  
xml-rpc. But it isn’t working. Everything seems to work but the  
resulting mp3 won’t play in my browser. I think the encoding is  
getting garbled somehow, but I’m new to this and can’t spot the  
problems. Can anyone help?

Code sample below. Thanks!

## file: twitogram.rb

#!/usr/bin/ruby

#usage: twitogram.rb myfile.mp3

require “xmlrpc/client”  
require “base64”

username = ‘twitter\_user’  
password = ‘twitter\_pass’

#slurp into string  
mp3\_string = open(ARGV[0], ‘rb’) { |f| f.read }

mp3bits = Base64.encode64(mp3\_string)

# Make an object to represent the XML-RPC server.

server = XMLRPC::Client.new( “[rpc.twittergram.com](http://rpc.twittergram.com)”, “/RPC2”)

# Call the remote server and get our result

result = server.call(“twittergram.newPost”, username, password,  
mp3bits)

puts “#{result}”

---

<div class="post-metadata">

**Author:** ![phildog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/db5fbb/32.png) [@phildog](https://www.ruby-forum.com/u/phildog)\
**Post date:** [June 28, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/need-help-posting-a-base64-encoded-binary-via-xml-rpc/108032/2 "2007-06-28T16:36:42Z")

</div>

Never mind folks. I found working sample code here:  
[http://dotnet.org.za/armand/archive/2007/06/26/twittergrams.aspx](http://dotnet.org.za/armand/archive/2007/06/26/twittergrams.aspx)
