title: Sending base64binary (image) via SOAP with ruby / savon
body: <p>I'm using SOAP api for allegro.pl (polish alternative for ebay.com) and I've a litte problem with sending images through SOAP. I was asking the same question at official forum but unfortunately no-one has replied.</p>
  
  <p>Anyway, working (piece of) code (soap message) in PHP looks like that:</p>
  
  <pre><code>array(
  'fid' =&gt; 16,
  'fvalueImage' =&gt; file_get_contents('http://www.stropna_www.pl/images/obrazek.jpg') 
  </code></pre>
  
  <p><em>note this is not a full soap message, but this one which made me not sleeping this night</em></p>
  
  <p>And it works (well, in documentation it works, I cannot be sure as I do not use PHP (neither do I know it)). <strong>I was looking for equivalent for file_get_contents</strong> in ruby and I was trying to use net/http and open-uri to open file from the url and even tried to use </p>
  
  <pre><code>img = File.open('img.jpg', 'rb') { |f| f.read }
  </code></pre>
  
  <p>but every time I try, server returns invalid XML.</p>
  
  <p><strong>When I try to send the request without image it works correctly.</strong></p>
  
  <hr>
  
  <p>Here's the full code in Ruby:</p>
  
  <pre><code>def self.do_new_auction_ext 
  img = File.open('img.jpg', 'rb') { |f| f.read }
  
  xml_message = prepare_message("DoNewAuctionExtRequest", {
    :sessionHandle =&gt; self.session_id,
    :fields =&gt; [
      { :fid =&gt; 1,                                # Tytuł
        :fvalueString =&gt; "Oferta Testowa ze zdjeciem", },       # TODO: Zmienne?
      { :fid =&gt; 2,                                # Kategoria
        :fvalueInt =&gt; 1834 },                       # TODO: Zmienne?
      { :fid =&gt; 4,                                # Czas trwania
        :fvalueInt =&gt; 3 },                          # 1 - 3 dni, 2 - 7 dni, 3 - 10 dni
      { :fid =&gt; 5,                                # Ilość
        :fvalueInt =&gt; 12},                          # TODO: Zmienne?
      { :fid =&gt; 8,                                # Cena kup teraz
        :fvalueFloat =&gt; 50.00},                     # TODO: Zmienne?
      { :fid =&gt; 9,                                # Kraj
        :fvalueInt =&gt; 228},                         # 1 - Polska, 228 - Neverland
      { :fid =&gt; 10,                               # Wojewodztwo
        :fvalueInt =&gt; 215},                         # Lewopolskie
      { :fid =&gt; 11,                               # Miejscowość
        :fvalueString =&gt; "Bielsko-Biala"},
      { :fid =&gt; 14,                               # Formy platnosci
        :fvalueInt =&gt; 1 },                          # Płatne z góry przelewem
      { :fid =&gt; 16,                               # Zdjecie 1
        :fvalueString =&gt; img },
      #{ :fid =&gt; 15,                               # Opcje dodatkowe
      #  :fvalueInt =&gt; 2},
      { :fid =&gt; 24,                               # Opis
        :fvalueString =&gt; "konik"},
      { :fid =&gt; 28,                               # Sztuki / Komplety / Pary
        :fvalueInt =&gt; 1},
      { :fid =&gt; 32,                               # Kod pocztowy
        :fvalueString =&gt; "43-300"},
      { :fid =&gt; 35,                               # Darmowe opcje przesylki
        :fvalueInt =&gt; 2}                          # 1 - Odbior osobisty, 2 - e-mail, 4 - Odbior osobisty po przedplacie
    ]
  })
  
  # puts xml_message
  
  response = @client.call(:do_new_auction_ext) do
    xml xml_message
  end
  </code></pre>
  
  <p><em>don't mind polish comments</em></p>
  
  <p>prepare_message function only creates xml which goes to the server, and I'm quite sure it's working correctly as w/o image the server responds as it should (it works!)</p>
  
  <p>but, with the image sent the server responded with</p>
  
  <pre><code>{:fault=&gt;{:faultcode=&gt;"Sender", :faultstring=&gt;"Invalid XML"}}
  </code></pre>
  
  <p>and here is <a href="http://wrzasq.pl/blog/allegro-webapi-tutorial-vol-2.html" rel="nofollow">website with working PHP code</a> <em>website is in polish, but code is in PHP</em></p>
  
  <p>and lastly, <a href="http://allegro.pl/webapi/documentation.php/show/id,113" rel="nofollow">here is the documentation</a> <em>it's also in polish, but includes english naming and additional PHP code under "Przykłady wywołań" tab</em></p>
  
  <p>I'm using Ruby 1.9.3 and savon to send all SOAP request (which works, but sending the image doesn't).</p>
  
  <hr>
  
  <p>Apologies for the wall of text but I was trying to explain this best I can. 
  Thanks in advance for any help, and thank you even for reading this :)</p>