有人能够通过 Confluence.pm 添加附件吗?
如果可以的话可以提供一下代码吗。 我几乎可以做所有其他事情,从创建新页面、修改页面属性等。但我似乎无法添加附件。 我已阅读官方 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你已经完成了 95% 的任务。 对我来说,秘诀是:
我确信这已经太晚了,无法提供帮助,但也许有一天其他人会遇到它。
You were 95% of the way there. The secret sauce for me:
I'm sure this is way too late to be helpful, but maybe someone else will bump into it some day.
尝试看看 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.
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.