title: Has anyone been able to get Confluence.pm to add attachments?
body: <p>If so can you provide the code. I am able to do almost everything else from creating new pages, modifying page attributes etc.. But I cannot seem to add attachments. I have read the official <a href="http://confluence.atlassian.com/display/CONFEXT/Perl+XML-RPC+client" rel="nofollow noreferrer">conflunce Perl XML-RPC site and discussions</a> but all the code fragments they show there don't seem to work for me.  Here is my hacked up attempt at it:</p>
  
  <pre><code># The following command sort of worked:
  # ~/bin/wikitool.pl -action attach_file -url $MYURL
  # IT attached something but the file was empty
  sub attach_file {
      my $confluence = XMLRPC::Lite-&gt;proxy($opts{server}."rpc/xmlrpc");
      my $token = $confluence-&gt;call("confluence1.login", $opts{login}, $opts{password})-&gt;result();
  
      # Fetch page
      my $page = FetchPage($opts{title});
      if (not $page) {
        dbg("$opts{title} page is missing.","FATAL");
      }
  
      my $pageId = SOAP::Data-&gt;type( string =&gt; $$page{id} );
  
      my $filename = "$ENV{HOME}/tmp/tmp0.gif";
      my $metadata = {
          fileName =&gt; $filename,
          contentType =&gt; "image/gif",
          comment =&gt; "Some random GIF",
      };
      if (not open FILE, "&lt; $filename") {
          dbg("Could not open file $filename: $!\n","FATAL");
      }
      binmode FILE;
      my $data;
      $data .= $_ while (&lt;FILE&gt;);
      my $call = $confluence-&gt;addAttachment($pageId, $metadata, $data);
  
      my $fault = $call-&gt;fault();
      if (defined $fault) {
          dbg("could not attach $filename" . $call-&gt;faultstring(), "FATAL");
      }
      else {
        print "attached $filename\n";
      }
  }
  </code></pre>