我想将带有 Groovy 脚本的文件上传到 Confluence。 作为这个 Pythonscript 示例! 我开始将代码翻译成 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 )