perl – 有没有人能够通过Confluence.pm添加附件?

前端之家收集整理的这篇文章主要介绍了perl – 有没有人能够通过Confluence.pm添加附件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果是这样,你可以提供代码.我几乎可以做任何其他事情,从创建新页面,修改页面属性等.但我似乎无法添加附件.我已经阅读了官方的 conflunce Perl XML-RPC site and discussions,但是他们在那里显示的所有代码片段似乎对我都不起作用.这是我对它的黑客攻击:

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

解决方法

你有95%的路在那里.给我的秘诀:

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

我确信现在为时已晚,无法提供帮助,但也许其他人有一天会碰到它.

猜你在找的Perl相关文章