سؤال

I want upload a file with a Groovy script to Confluence. As this Pythonscript example! I started to translate the code into 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!!!

but i found nothing in groovy for the last steps!

//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));

I think, i must have an object for the attachments and a method to store the attachment on the given page in the server.

FINAL WORKING CODE

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 )
هل كانت مفيدة؟

المحلول

Looking at the docs, it looks like you should be able to do:

server.confluence2.addAttachment( token,
                                  page.id,
                                  [ fileName: file.name,
                                    contentType:'application/pdf' ],
                                  file.bytes )
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top