0

在工作流转换中,我有一个带有“附加文件”输入的屏幕。在后期功能中,我想访问附件(如果有)并使用该文件作为附件创建另一个问题。

我试图通过 ServletActionContext.getRequest() 来实现这一点,但我似乎无法以这种方式获取上传的文件。HttpServletRequest 没有 getPart() 函数。

是否有从后期功能访问附件的官方方法?

提前谢谢了

4

1 回答 1

0

感谢Naykipap的这个回答,我找到了一个可行的解决方案。这是我想出的:

// 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 中没有 changeItems 和/或附件未保存到磁盘。我把它移到了处决的最后,对我来说效果很好。

于 2012-10-24T09:42:00.260 回答