multipart-stream.js 531 B

12345678910111213141516171819202122232425
  1. var needle = require('./../');
  2. var url = 'http://posttestserver.com/post.php?dir=needle';
  3. var black_pixel = Buffer.from("R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=", 'base64');
  4. var data = {
  5. foo: 'bar',
  6. nested: {
  7. test: 123
  8. },
  9. image: { buffer: black_pixel, content_type: 'image/gif' }
  10. }
  11. var resp = needle.post(url, data, { multipart: true });
  12. resp.on('readable', function() {
  13. while (data = this.read()) {
  14. console.log(data.toString());
  15. }
  16. })
  17. resp.on('done', function(data) {
  18. console.log('Done.');
  19. })