Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda