Scriptrunner REST Endpoint MultiPart Form Data

I'm trying to upload a file to a scriptrunner REST custom end point. The file upload is being initiated from a dialog box with the following code


(function ($) {
    $("#dialog-close-button").click(function (e) {
    $("#img-form").submit(function(e) {
        var fd = new FormData($("#img-form").get(0));
            type: "POST",
            data: fd,
            url: "/rest/scriptrunner/latest/custom/adminImgUploadDialogSave",
            dataType   : 'json',
            processData: false,
            contentType: false,
            headers: {
                'Content-Type' : 'multipart/form-data',
                'X-Atlassian-Token': 'no-check',
                'Access-Control-Allow-Origin' : '*'
        }).done(function(response) {
            if (response.status=="ok") {
        return false;

In the rest endpoint I have

import groovy.transform.BaseScript
import groovy.json.JsonBuilder
import javax.servlet.http.HttpServletRequest

@BaseScript CustomEndpointDelegate delegate

    httpMethod: "POST", groups: ["jira-administrators"]
) { MultivaluedMap queryParams, String body, HttpServletRequest req ->
    //if (filename==null) {
    //    return Response.ok(new JsonBuilder([status: 'not ok']).toString()).build()
    //} else {
    //    do stuff
    //    return Response.ok(new JsonBuilder([status: 'ok']).toString()).build()

body contains what I would expect

    Content-Disposition: form-data; name="atl_token"
    Content-Disposition: form-data; name="image"; filename="nodetype-child.png"
    Content-Type: image/png
    lots of binary data

but req.getParts() always returns an empty list.

How do I load/parse the form data?






1 answer

Hey, Daniel. So, after hacking with this at length, I concluded that there's not a really robust way to do this with ScriptRunner out of the box. Like you, I was able to hack together something that handled uploading basic text files, but images proved more problematic. I've submitted a bug report for that.

We may just end up documenting a working example or pointing people to how to roll their own REST Endpoint using JAX, but you can watch that for further developments on multipart support in ScriptRunner REST Endpoints.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

268 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you