2009-06-12 10 views
5

Se così è possibile fornire il codice. Sono in grado di fare quasi tutto il resto dalla creazione di nuove pagine, dalla modifica degli attributi di pagina ecc. Ma non riesco a aggiungere allegati. Ho letto l'ufficiale conflunce Perl XML-RPC site and discussions ma tutti i frammenti di codice che mostrano non sembrano funzionare per me. Ecco il mio tentativo hacked:Qualcuno è riuscito a ottenere Confluence.pm per aggiungere allegati?

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

risposta

5

Eri al 95% del modo in cui ci sei. La salsa segreta per me:

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

Sono sicuro che questo è troppo tardi per essere utile, ma forse qualcun altro si imbatterà in esso un giorno.

+0

Grazie! Sono passato ad altri progetti ma grazie per l'aggiunta di alcune intuizioni al collettivo ... – stephenmm

0

xml-rpc è ora deprecato in confluenza. attualmente molte funzioni non funzionano nell'interfaccia xml-rpc. più funziona sotto sapone.

Problemi correlati