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

102
Views
Creat ReadStream object from JSON object

I am using jira-client npm to deal with jira rest API , and I am trying to add an attachment to a ticket using addAttachmentOnIssue method, this method requires the key of the issue as a string parameter and also requires ReadStream as the second parameter, I am able to attach a file to a ticket if I followed these steps:

var jiraAPI = require('jira-client');
var jira = new JiraApi({
protocol: "https",
host:"myJiraInstance",
username:"myUserName",
password: "MyToken",
apiVersion: "2",
strictSSL: true,})

then

const fileStream = fs.createReadStream(filePath);
jira.addAttachmentOnIssue(tickeID,fileStream);

As you can see I have the filepath and I attached it but I that is not what I want, I want to create a file from JSON object, without writing this file on the system and then send it

is that possible ?

by using:

var stream = require('stream');
var readable = new stream.Readable(); // new empty stream.Readable
readable.push('some data');
readable.push(null);
jira.addAttachmentOnIssue(tciketID,readable)

I am getting:

Processing of multipart/form-data request failed. Stream ended unexpectedly
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the problem is that the required file related information such as filename, knownLength etc. is missing, which is why it fails parsing the stream.

you need to provide file related information manually

as jira-client is using postman-request, you can do that by providing a custom file object like described here: multipart/form-data (Multipart Form Uploads)

Try this:

var JiraApi = require('jira-client');
var jira = new JiraApi({
    protocol: "https",
    host: "myJiraInstance",
    username: "myUserName",
    password: "MyToken",
    apiVersion: "2",
    strictSSL: true
})



const inputData = JSON.stringify({
    someProp: 'some data'
});

var stream = require('stream');
var readable = new stream.Readable();
readable.push(inputData);
readable._read = () => {};
readable.push(null);


// https://www.npmjs.com/package/postman-request#forms
// Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}
// Use case: for some types of streams, you'll need to provide "file"-related information manually.
// See the `form-data` README for more information about options: https://github.com/form-data/form-data
const myStreamFile = {
    value: readable,
    options: {
        filename: 'json.json',
        contentType: 'application/json',
        knownLength: inputData.length
    }
}


jira.addAttachmentOnIssue(tciketID, myStreamFile)
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!