Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Add attachemet to a ticket using xhr2 for jira rest api

I am trying to upload a file to a ticket using Jira rest api and xhr2 using node.js with electron

Here is my code

var XMLHttpRequest = require('xhr2')
var xhr = new XMLHttpRequest();
const fs = require('fs');
const filePath = 'test2.txt';
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('file', fileStream, {knownLength: fileSizeInBytes});
xhr.open("POST", "https:/myInstance/rest/api/2/issue/ticketid/attachments", true);
xhr.setRequestHeader("Authorization" , "Basic "+ Buffer.from("user" + ":" + "token").toString("base64"));
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('X-Atlassian-Token','no-check');
xhr.send(form);

I am getting the following error:

unsupported send() data [object FormData]

I am able to attach a file using: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post example

but I want to know what is the problem with my previous code

I tried to add these to the header:

xhr.setRequestHeader('processData', false);
xhr.setRequestHeader('contentType',false);

it didn't help, also I tried to add:

xhr.setRequestHeader("Content-type", "multipart/form-data");

also it didn't work

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is in xhr itself in the documentation it was mentioned that:

The following standard features are not implemented.

FormData
Blob
file:// URIs
data: URIs
upload progress events
synchronous operation
Same-origin policy checks and CORS
cookie processing
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!