使用Groovy将文件上传到Confluence?

3
我想使用Groovy脚本上传文件到Confluence。 就像这个Python示例一样! 我已经开始将代码翻译成Groovy。
// Groovy
def server = new XMLRPCServerProxy("http://confluence:8090/rpc/xmlrpc")
def spaceKey = "Area"
def pageTitel = "FileUpload"
def contentType = "application/pdf"
def token = server.confluence2.login("UserName","Password")
def page  = server.confluence2.getPage(token, spaceKey, pageTitel)
def fileName  = "D:\\datamodel.pdf"
def file = new File (fileName)    
//
//Up to this point it works!!!

但是我在Groovy中没有找到最后几步的内容!
//Python Script from Examplelink above
//.....
attachment = {};
attachment['fileName'] = os.path.basename(filename);
attachment['contentType'] = contentType;

server.confluence1.addAttachment(token, page['id'], attachment, xmlrpclib.Binary(data));

我认为,我需要一个附件对象和一种将附件存储在服务器上给定页面的方法。
最终可用代码。
def server = new XMLRPCServerProxy("http://confluence:8090/rpc/xmlrpc")
def spaceKey = "Area"
def pageTitel = "FileUpload"
def fileName  = "D:\\datamodel.pdf"
def contentType = "application/pdf"
def token = server.confluence2.login("UserName" , "Password")
def page  = server.confluence2.getPage(token, spaceKey, pageTitel)
def file = new File (fileName)
server.confluence2.addAttachment( token, page.id, [ fileName: file.name, contentType:contentType ], file.bytes )

1
你尝试过使用 server.confluence2.addAttachment( token, page.id, [ fileName: file.name, contentType:'application/pdf' ], file.bytes ) 吗? - tim_yates
很酷 :-) 我已经将其添加为答案,之前我不确定 :-) - tim_yates
你能分享一下你的最终代码吗? - webwesen
请参见上面的最终工作代码。 - Laba42
1个回答

1

从文档上看,你应该能够这样做:

server.confluence2.addAttachment( token,
                                  page.id,
                                  [ fileName: file.name,
                                    contentType:'application/pdf' ],
                                  file.bytes )

请翻译以下与编程有关的内容,从英语到中文。只返回翻译后的文本:[这里] (https://developer.atlassian.com/display/CONFDEV/Confluence+XML-RPC+and+SOAP+APIs), [这里] (https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Data+Objects) 和 [这里] (https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods)(特别是最后一个) - tim_yates

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接