使用Groovy将文件上传到Confluence?

时间:2013-07-09 10:10:27

标签: groovy xml-rpc confluence

我想将带有Groovy脚本的文件上传到Confluence。 As this Pythonscript example! 我开始将代码翻译成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!!!

但是我在最后一步中没有找到任何内容!

//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 个答案:

答案 0 :(得分:1)

查看文档,看起来你应该能够做到:

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