I've tried to work out with various questions already asked and the api docs.
I've not been able to work out how to post attachments to an issue using scriptrunners Groovy.
My goal is to get all the attachment URLs from one issue and add them to another issue.
def attachments = get("/rest/api/3/issue/${projectIssueKey}").asJson().body.array[0].fields.attachment
attachments.each{
def filename = it.filename
def fileUrl = it.content
def fileBody = get("${fileUrl}").asBinary().body
// POST attachment
def resp = post("/rest/api/3/issue/${newProjectIssueKey}/attachments")
resp
}
It's at the post attachment part that I'm not sure what to do.
String key = "${issueKey}"
def newBody = get("${imageURL}").asBinary().body
InputStream stream = new ByteArrayInputStream(newBody.getBytes())
def resp = Unirest.post("/rest/api/3/issue/${key}/attachments")
.header("X-Atlassian-Token", "no-check")
.field('file', stream, 'image002.png')
.asJson()
resp
I've now got to this!
But I guess the upload is not being done correctly as there is an attachment but the size is 0.0kb
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.