2

I want to send a POST request that includes some data and a file in Node.js. I'm using the "request" library (alternatives are fine).

How do I include a "file" in the request data?

var request = require("request");

request.post({
  url: "https://sender.blockspring.com/api/blocks/319bfef4aad7f3477745048a2da3ae6a?api_key=2e0ef0c216078d60630d1321e67b243a",
  form: { first_name: "Don", last_name: "P", my_file: ???? }
},
function(err, response, body) {
  console.log(body);
});
Don P
  • 60,113
  • 114
  • 300
  • 432
  • 1
    just started looking at - https://github.com/felixge/node-form-data maybe this will work – Don P Jul 25 '14 at 00:53
  • 1
    Yes, that is exactly what you should be looking at. Multi-part forms is what you need. – Brad Jul 25 '14 at 01:02
  • http://stackoverflow.com/questions/13797670/nodejs-post-request-multipart-form-data – eddie Jul 25 '14 at 01:11

0 Answers0