在工作流转换中,我有一个带有“附加文件”输入的屏幕。在后期函数中,我想访问附件(如果有的话),并将此文件作为附件创建另一个问题。
我试图通过ServletActionContext.getRequest()实现这一点,但我似乎无法以这种方式获取上传的文件。 HttpServletRequest没有getPart()函数。
是否有官方方式从后期功能访问附件?
非常感谢提前
答案 0 :(得分:0)
感谢Naykipap的this回答,我找到了一个有效的解决方案。这就是我想出的:
// copy attachments uploaded in screen to new issue
def changeItems = transientVars["changeItems"]
def uploadChanges = changeItems.findAll { item -> item.getField() == "Attachment" && item.getFieldType() == "jira" }
uploadChanges.each { uploadChange ->
def Attachment attachment = attachmentManager.getAttachment(uploadChange.getTo()?.toLong())
if (attachment) {
def filePath = PathUtils.joinPaths(pathManager.attachmentPath, currentIssue.projectObject.key, currentIssue.key, attachment.id.toString())
def atFile = new File(filePath)
if (atFile.canRead()) {
log.debug("Cloning attachment ${attachment.filename}")
attachmentManager.createAttachmentCopySourceFile(atFile, attachment.filename, attachment.mimetype, attachment.author, newIssue, [:], attachment.created)
}
}
}
重要说明:在将问题保存到db后,必须执行脚本。否则,transientVars中没有changeItem和/或附件未保存到磁盘。我把它一直移到执行结束时,它对我来说很好。