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

377
Vistas
Sending a local file as a 'File' in post request through NodeJs

I am trying to call this api using nodejs - https://developer.zebra.com/apis/sendfiletoprinter-model#/SendFileToPrinter/SendFiletoPrinter

It accepts a zpl_file as a string(binary) it says in the documentation.

I have a locally stored zpl file and want to attach it to my post request using NodeJs code.

This is the code I have so far, but I can't get it to work. Any help on this would be highly appreciated. Thanks!

exports.PrintUsingExampleCode = async function(payload) {

let url = "https://api.zebra.com/v2/devices/printers/send";
let apikey = "<apikey>"; 
let tenant = "<tenant>"; 
let sn = "<printerSN>";              
let filepath = 'C:\\ZPL\\HelloWorld.zpl'

var req = require('request');
var fs = require('fs');

var fileToSend = fs.readFile('C:\\ZPL\\HelloWorld.txt');

req.post({
   url: url,
   form: { sn: sn, tenant: tenant, apikey: apikey, zpl_file : fileToSend
  },
   headers: { 
      'sn': sn,
      'apikey' : apikey,
      'tenant' : tenant
   },
   method: 'POST'
  },

  function (e, r, body) {
      console.log(body);
  });

};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

pass the file as a readable stream and serial number in the form part, and apiKey and tenant as headers:

let url = "https://api.zebra.com/v2/devices/printers/send";
let apikey = "<apikey>";
let tenant = "<tenant>";
let sn = "<printerSN>";
let filepath = 'C:\\ZPL\\HelloWorld.zpl'

var req = require('request');
var fs = require('fs');

var fileToSend = fs.createReadStream(filepath);

req.post({
        url: url,
        formData: {
            sn: sn,
            zpl_file: fileToSend
        },
        headers: {
            'apikey': apikey,
            'tenant': tenant
        },
        method: 'POST'
    },

    function(e, r, body) {
        console.log(body);
    });
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