Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script for adding default attachment to issue showing error (No such file or directory)

kanishka May 18, 2020

Hi 

I have added post function script, it is showing error "

com.atlassian.jira.web.util.AttachmentException: Got error while saving attachment Testing.txt: Got exception while saving attachment in attachment store. Exception: C:/Users/kbharadwaj/Downloads/Testing.txt (No such file or directory)

Here is my code :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean

def attachmentManager = ComponentAccessor.getAttachmentManager()

def user = ComponentAccessor.getJiraAuthenticationContext()?.loggedInUser

String pathToFile = "C:/Users/kbharadwaj/Downloads/"
String fileName = "Testing.txt"
String pathAndFile = pathToFile+fileName

def bean = new CreateAttachmentParamsBean.Builder()
.file(new File(pathAndFile))
.filename(fileName)
.contentType("text/txt")
.author(user)
.issue(issue)
.copySourceFile(true)//you must do this otherwise it deletes the source file from the file system
.build()
attachmentManager.createAttachment(bean)

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events