It looks like you are already using request module .
in this case, all you need to send multipart/form-data is to use the form function:
var req = request.post(url, function (err, resp, body) { if (err) { console.log('Error!'); } else { console.log('URL: ' + body); } }); var form = req.form(); form.append('file', '<FILE_DATA>', { filename: 'myfile.txt', contentType: 'text/plain' });
but if you want to publish any existing file from your file system, you can simply pass it as a readable stream:
form.append('file', fs.createReadStream(filepath));
request will retrieve all associated metadata on its own.
For more information on publishing multipart/form-data see the node-form-data module , which is internally used by request .
Leonid Beschastny Aug 17 '14 at 0:00 a.m. 2014-08-17 00:00
source share