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

384
Views
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 answers
Answer question

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 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!