How to name a file parameter when uploading an image with node request?


I'm using request module ( to fetch an image and I want to pipe it to a third-party api.

Something like this:


Now, I'm not sure how to do a few things.

  1. How do I name the post parameter?

  2. How to add other form fields, like API key and other data?

  3. How to make the header of my post request 'multipart/formdata'?

Problem courtesy of: Zlatko



For multipart/form-data we use the form-data library by @felixge. You don’t need to worry about piping the form object or setting the headers, request will handle that for you.

var r ='')    
var form = r.form()    
form.append('my_field', 'my_value')    
form.append('my_buffer', new Buffer([1, 2, 3]))     
form.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png'))     
form.append('remote_file', request(''))     

Also see

Solution courtesy of: twilson63


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.