gpt4 book ai didi

groovy - 文件上传与 Groovy 融合?

转载 作者:行者123 更新时间:2023-12-01 15:39:20 26 4
gpt4 key购买 nike

我想将带有 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!!!

但我在 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 )

最佳答案

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

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

关于groovy - 文件上传与 Groovy 融合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17545574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com