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

213
Views
Node only writes half of binary data

This is my simple express service:

let express = require('express'),
    fs      = require('fs'),
    path    = require('path');

var app = express();
app.set("json spaces", 2);
app.use(express.static(__dirname + "/static"));

app.use(function(req, res, next) {
  var data = new Buffer('');
  req.on('data', function(chunk) {
      data = Buffer.concat([data, chunk]);
  });
  req.on('end', function() {
    req.rawBody = data;
    next();
  });
});

app.post("/upload/:filename", function(req, res) {
    let path = "/tmp/" + req.params.filename;
    fs.writeFile(path, req.rawBody, "binary", function(error) {
        res.send({
            message: "sadfasdf"
        });
    });
});

app.listen(3001, function() {
    console.log("Started!");
});

I'm doing this to upload the binary data:

curl -H "Content-Type: application/octet-stream" -X POST http://localhost:3001/upload/test.tiff -d @/home/vagrant/test.tiff

For a file that is about 1100kb, it will only actually write about 622kb. Can someone tell me what is going wrong?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It was the way I was using curl that was the problem. I was using -d and should have been using --data-binary instead.

about 4 years ago · Santiago Trujillo 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!