views:

332

answers:

2

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 conflunce Perl XML-RPC site and discussions but all the code fragments they show there don't seem to work for me. Here is my hacked up attempt at it:

# 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";
    }
}
A: 

Well, I had to give up on getting it working with perl and I tried the Python version and I got it working after some work. I now have a newfound hatered for Python! Sorry, don't want to make enemies but the fact that so many things have been depricated on different versions of Python make it very difficult to produce robust scripts that work on many different severs. You have to find the commonality between the different versions and only use those things that have been steady in Python! Not very easy and I still am not confidient it won't break... I never did like the indention stuff but that was just a stylistic complaint but now I have a much more pragmatic complaint. I guess there are problems with every language and you just know how bad each one is until you use it and it HAS to work on different servers...

stephenmm
-1 for posting a rant disguised as an update.
Jeremy Wall
It was an update and a rant. Thank you.
stephenmm
+1  A: 

You were 95% of the way there. The secret sauce for me:

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

I'm sure this is way too late to be helpful, but maybe someone else will bump into it some day.

Bryant
Thanks! I have moved on to other projects but thanks for adding some insight to the collective...
stephenmm