最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: incorrect header check when running post - Stack Overflow

programmeradmin2浏览0评论

I need to get zip from rest call (for simulation I use postman with binary option for post and add a little zip file with folder and html file),during the simulation I want to get the data with express and extract the zip and put in some folder under C drive. Currently when I run the following program(this is all the code which i've tried) but im getting error

events.js:85 throw er; // Unhandled 'error' event ^ Error: incorrect header check at Zlib._handle.onerror (zlib.js:366:17)

var express = require('express'),
    fs = require('fs'),
    zlib = require('zlib'),
    app = express();

app.post('/', function (req, res) {
    var writeStream = fs.createWriteStream('C://myFolder', {flags: 'w'});
    req.pipe(zlib.createInflate()).pipe(writeStream);

});

var server = app.listen(3000, function () {
        console.log("Running on port" + 3000)
    }
)

in postman header i've added the following

content-Type ----> application/zip

How should I overe this issue and save the zip ? there is other remended (zlib)library to get extract and save zip?

I need to get zip from rest call (for simulation I use postman with binary option for post and add a little zip file with folder and html file),during the simulation I want to get the data with express and extract the zip and put in some folder under C drive. Currently when I run the following program(this is all the code which i've tried) but im getting error

events.js:85 throw er; // Unhandled 'error' event ^ Error: incorrect header check at Zlib._handle.onerror (zlib.js:366:17)

var express = require('express'),
    fs = require('fs'),
    zlib = require('zlib'),
    app = express();

app.post('/', function (req, res) {
    var writeStream = fs.createWriteStream('C://myFolder', {flags: 'w'});
    req.pipe(zlib.createInflate()).pipe(writeStream);

});

var server = app.listen(3000, function () {
        console.log("Running on port" + 3000)
    }
)

in postman header i've added the following

content-Type ----> application/zip

How should I overe this issue and save the zip ? there is other remended (zlib)library to get extract and save zip?

Share Improve this question edited Jul 16, 2015 at 5:53 07_05_GuyT asked Jul 15, 2015 at 18:59 07_05_GuyT07_05_GuyT 2,88715 gold badges48 silver badges92 bronze badges 1
  • I dont think postman can handle this. Did you try sending a curl request somehow? – Gogol Commented Jul 15, 2015 at 19:45
Add a ment  | 

1 Answer 1

Reset to default 2

zlib is meant to extract gzipped or deflated data, not .ZIP files.

You can use the node-unzip module for those:

var unzip = require('unzip');
...
app.post('/', function(req, res) {
  var extractor = unzip.Extract({ path : 'C://myFolder' }).on('close', function() {
    res.sendStatus(200);
  }).on('error', function(err) {
    res.sendStatus(500);
  });
  req.pipe(extractor);
});

If Postman can't handle uploads like this (as suggested in the ments), you can test using cURL:

$ curl -XPOST localhost:3000 --data-binary @test.zip
发布评论

评论列表(0)

  1. 暂无评论