skip to Main Content

I’m using NodeJs to try to upload an attachment to a Jira Issue via the Jira Rest API.

The api expects multipart/form-data so this is how I’m calling it in Node:

function uploadAttachments(supportFormData, callback) {
    const url =
      'https://somewhere.com/jira/rest/api/2/issue/' +
      supportFormData.issueId +
      '/attachments';

    var options = {
      url: url,
      headers: {
        Authorization: { user: username, password: password },
        'X-Atlassian-Token': 'nocheck'
      }
    };

    var r = request.post(options, function(err, res, body) {
      if (err) {
        console.error(err);
        callback(false);
      } else {
        console.log('Upload successful!  Server responded with:', body);
        callback(false);
      }
    });

    var form = r.form();
    form.append('file', supportFormData.attachments[0].contents, {
      filename: supportFormData.attachments[0].fileName,
      contentType: supportFormData.attachments[0].contents
    });
  }

The error I’m receiving is:

org.apache.commons.fileupload.FileUploadException: Header section
has more than 10240 bytes (maybe it is not properly terminated)

The “supportFormData.attachments[0].contents” is ofType Buffer.

Any suggestions as to what could be causing this error?

2

Answers


  1. If its a basic auth change options object to

    let auth = new Buffer(`${username}:${password}`).toString('base64');
    var options = {
          url: url,
          headers: {
            Authorization: `Basic ${auth}`,
            'X-Atlassian-Token': 'nocheck'
          }
        };
    Login or Signup to reply.
  2. I ran into this same issue and it turns out JIRA (or Java) requires rn as new line character. After I changed n to rn my requests went through without problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search