Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

376
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda