need help posting a base64-encoded binary via xml-rpc

Discussion in 'Ruby' started by phildog, Jun 28, 2007.

  1. phildog

    phildog Guest

    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", "/RPC2")

    # Call the remote server and get our result
    result = server.call("twittergram.newPost", username, password,
    mp3bits)

    puts "#{result}"
     
    phildog, Jun 28, 2007
    #1
    1. Advertising

  2. phildog

    phildog Guest

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

    On Jun 28, 10:08 am, phildog <> wrote:
    > 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", "/RPC2")
    >
    > # Call the remote server and get our result
    > result = server.call("twittergram.newPost", username, password,
    > mp3bits)
    >
    > puts "#{result}"
     
    phildog, Jun 28, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. T

    decode base64 encoded login info

    Mr. T, Mar 5, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    524
    Patrice
    Mar 5, 2007
  2. Ymtrader
    Replies:
    1
    Views:
    585
    Adam Tauno Williams
    Mar 15, 2011
  3. Phil C.
    Replies:
    2
    Views:
    453
    Phil C.
    Jul 19, 2005
  4. Mr. T

    decode base64 encoded login info

    Mr. T, Mar 5, 2007, in forum: ASP .Net Security
    Replies:
    0
    Views:
    180
    Mr. T
    Mar 5, 2007
  5. Michael

    Base64-Encoded URL in ASP

    Michael, Feb 23, 2004, in forum: ASP General
    Replies:
    1
    Views:
    327
    Chris Barber
    Feb 24, 2004
Loading...

Share This Page