gpt4 book ai didi

perl - 有没有人能够让 Confluence.pm 添加附件?

转载 作者:行者123 更新时间:2023-12-04 12:26:25 24 4
gpt4 key购买 nike

如果可以,能否提供代码。从创建新页面、修改页面属性等,我几乎可以做所有其他事情。但我似乎无法添加附件。我看过官方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, $metadata, $escaped_data);

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

关于perl - 有没有人能够让 Confluence.pm 添加附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/989485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com