Has anyone been able to get Confluence.pm to add attachments?

If so, you can provide the code. I can do almost everything else from creating new pages, changing page attributes, etc. But I can not add attachments. I read the official conflunce Perl XML-RPC website and discussions , but all the code snippets that they show there do not seem to work for me. Here is my hacking attempt:

# 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->proxy($opts{server}."rpc/xmlrpc");
    my $token = $confluence->call("confluence1.login", $opts{login}, $opts{password})->result();

    # Fetch page
    my $page = FetchPage($opts{title});
    if (not $page) {
      dbg("$opts{title} page is missing.","FATAL");
    }

    my $pageId = SOAP::Data->type( string => $$page{id} );

    my $filename = "$ENV{HOME}/tmp/tmp0.gif";
    my $metadata = {
        fileName => $filename,
        contentType => "image/gif",
        comment => "Some random GIF",
    };
    if (not open FILE, "< $filename") {
        dbg("Could not open file $filename: $!\n","FATAL");
    }
    binmode FILE;
    my $data;
    $data .= $_ while (<FILE>);
    my $call = $confluence->addAttachment($pageId, $metadata, $data);

    my $fault = $call->fault();
    if (defined $fault) {
        dbg("could not attach $filename" . $call->faultstring(), "FATAL");
    }
    else {
      print "attached $filename\n";
    }
}
+5
source share
3 answers

You were 95% on the road. Secret sauce for me:

$data .= $_ while (<FILE>);
my $escaped_data = new RPC::XML::base64($data);
my $call = $confluence->addAttachment($pageId, $metadata, $escaped_data);

I am sure it is too late to be useful, but maybe someone will come across this one day.

+5
source

xml-rpc is no longer used in merging. many functions do not currently work in the xml-rpc interface. more work under the soap.

0
source

All Articles