有人能够通过 Confluence.pm 添加附件吗?

发布于 2024-07-23 09:44:35 字数 1446 浏览 5 评论 0原文

如果可以的话可以提供一下代码吗。 我几乎可以做所有其他事情,从创建新页面、修改页面属性等。但我似乎无法添加附件。 我已阅读官方 conflunce Perl XML-RPC 站点和讨论 但他们在那里显示的所有代码片段似乎都不适合我。 这是我的尝试:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太傻旳人生 2024-07-30 09:44:35

你已经完成了 95% 的任务。 对我来说,秘诀是:

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

我确信这已经太晚了,无法提供帮助,但也许有一天其他人会遇到它。

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.

你在我安 2024-07-30 09:44:35

尝试看看 Chery Chase 使用 SOAP 而不是 RPC 来处理附件。

请参阅 http://confluence.atlassian.com/display/DISC/Perl+ XML-RPC+client 已经在讨论中了。

Try having a look at Chery Chase's use of SOAP instead of RPC for attachments.

See http://confluence.atlassian.com/display/DISC/Perl+XML-RPC+client well down in the discussion.

默嘫て 2024-07-30 09:44:35

xml-rpc 现在在 Confluence 中已被弃用。 目前很多功能在 xml-rpc 接口中不起作用。 更多肥皂下的作品。

xml-rpc is deprecated now in confluence. a lot of function currently doesn't work in xml-rpc interface. more works under soap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文