I am creating an attachment on the server.
Now the bonus would be to automatically download it on the user's local storage (e.g. Downloads folder) when a certain transition is triggered.
Is there any way to do this. The browser only knows HTML and JavaScript so it only could be possible to use some Web technology.
Hi @Albert Cameron You can write a postfunction on the workflow transition to download attachment from JIRA via REST API. Refer this link for the method.
Ok. I understand. So by using this REST call I will get the URL of the attachment. But then I would have to use javaScript or HTML to download automatically. So where do I have to put this JavaScript code ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using REST API you can get the URL of the attachment, as well as download it. You can script it in groovy and add new post function to your workflow transition. Please find the instructions for adding a post function on this link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. From the postfunction I can call first the REST API to get the metadata . So the URL to get the actual File would be e.g. "self": "http://www.example.com/jira/rest/api/2.0/attachments/10000",
Now comes the difficult part. If I just call this URL for the actual file from the postfunction it doesn't help me. I need a way to return the file to the client.
So maybe I will need a Web Resource which I call to return the file.
You shouldn't forget that all this postfunction stuff happens on the server. But the file has to be returned to the client.
The only way to get the file on the client is to use JavaScript. I am pretty sure about that. But where to put the JavaScript . That is my question right now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My collegue just came up with a solution. He just uses a plain button. And this button calls a Web Resource. For our scenario this is fine. But I really would not know how to do this with a postfunction.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
At first, you can add an attachment to a test issue. Then using Get Issue method, get its metadata -
eg: https://example.com/rest/agile/1.0/issue/{issueID}
The response will contain an attachment’s content field (eg: "content":"https://example.com/jira/secure/attachments/10000/picture.jpg") which is URL for this attachment.
Now you can make a GET https://example.com/jira/secure/attachments/10000/picture.jpg request to download this attachment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please share what solution you have found out, it might be useful to others.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My collegue now just uses a simple button (implemented as a Scriptrunner Web Fragment) to send a request to a Jira REST module. This way when the api sends back the file it is automatically downloaded. Good idea.
But it has one disadvantage. If the REST api throws a WorkflowException it will not be shown to the jira user. So all the validation on the server is useless for the jira user. In a REST Api you normally send back an error Object. But as we now use a simple button we can not process this error object. Really bad in terms of showing the jira user appropriate error messages.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for sharing @Albert Cameron You can create a new answer to this question and mark it as accepted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.