C
C
Coder3212017-09-03 23:37:54
Node.js
Coder321, 2017-09-03 23:37:54

How to get headers to pipe?

There is such a code. I make a request, stream a file. But in order to save this file, I need to get its permission, which is in the header, but pipe fires before the on('response') event. How to get headers before the pipe starts?

const url = 'http://localhost:3589/file/upload?fileName=qwe.json'
let ext, id;
request.get(url)
    .on('response', function (response) {
        ext = response.headers['file-ext'];
        id = response.headers['stream-id'];
    })
    .pipe(createWriteStream(`doodle.${ext}`))

PS Maybe there are plugin modules other than request that are more suitable for my purpose?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question