node.js - pipe image request coming from frontend in nodejs with custom headers -


i need pipe image request coming frontend url in nodejs custom headers. have code works same without headers.

html:

<form id="imageform" method="post" enctype="multipart/form-data" action="/image/test" name="image-test-form">   <input type="file" accept="image/*" />   <input type="submit" /> </form> 

using express , request (this code works fine) :

app.post( '/image/test', (req, res, next) => {   var url = "http://www.somedomain.com/image/test";   var headers = {'h1': 'test', 'h2': 'header'}; // todo: send headers   req.pipe(request.post (url,req.body)).pipe(res)   .on('error', function(err) { res.status(500).send(err);}); }); 

i couldn't figure out how pass headers along request. tried use formdata , form in request, not working.

before piping, can add custom headers req.headers:

req.headers.h1 = 'test'; req.headers.h2 = 'header';  req.pipe(request.post (url,req.body)).pipe(res) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -