简体   繁体   English

如何从Jira的工作流过渡屏幕访问附件(常规)

[英]How to access attached file from workflow transition screen in jira (groovy)

In a workflow transition I have a screen with an "attach file" input. 在工作流过渡中,我有一个带有“附加文件”输入的屏幕。 In the post-function I want to access the attached file (if any) and create another issue with this file as attachment. 在后功能中,我要访问附件(如果有)并使用此文件作为附件创建另一个问题。

I tried to achieve this via the ServletActionContext.getRequest() but I can't seem to get the uploaded file this way. 我试图通过ServletActionContext.getRequest()实现此目的,但似乎无法以这种方式获取上载的文件。 The HttpServletRequest does not have the getPart() function. HttpServletRequest没有getPart()函数。

Is there an official way to access attached files from post-functions? 有没有一种正式的方法可以从职能部门访问附件?

Many thanks in advance 提前谢谢了

Thanks to this answer from Naykipap I found a working solution. 感谢Naykipap的这个回答,我找到了一个可行的解决方案。 Here's what I came up with: 这是我想出的:

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

Important: the script has to be executed after the issue is saved to db. 重要提示:将问题保存到db后必须执行脚本。 Else there is no changeItems in the transientVars and/or the attachment is not saved to disk. 否则,transientVars中没有changeItems和/或附件未保存到磁盘。 I moved it right down to the end of executions and it worked fine for me. 我将其直接移至处决的结尾,对我来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM