Run a fire GET request and get a node stream

I am trying to send as a formDatastream from the image I receive with request

The problem is that the request is requested after the request formData. Is there a way that I can pass an image request to recognize? but with the freedom to add parameters to formData?

eg:

var req = request({
  method: 'POST',
  url: 'http://www.foo.bar/api/v1/tag/recognize',
  formData: {
    image_file: request('http://visual-recognition-demo.mybluemix.net/images/horses.jpg'),
    param2: 'value2'
  },
  json: true,
});

How do I shoot:

request('http://visual-recognition-demo.mybluemix.net/images/horses.jpg') so the answer can be used in req

UPDATE: It seems that the title Content-Lengthis not in the file http://visual-recognition-demo.mybluemix.net/images/horses.jpg response
and you only getTransfer-Encoding: chunked

More here

+4
1

. , , ,

request.get('http://google.com/img.png').pipe(request.put('some_url'));  

- PUT.

: , . , String. encoding:null, .
-

request({
   url: 'some_url', //your image
   encoding: null  //returns resp.body as bytes
}, callback..)

( ), promises. , -

var request = require('request');

//1st
request('first_url', function (error, response, body) {
  if (!error && response.statusCode == 200) {

      //2nd
      request('other_url', function (error, response, body) {   
         //process resp
      });
  }
});  

, promises. , ​​ Bluebird , .

( fasion)

var Promise = require("bluebird");
Promise.promisifyAll(require("request"));

request.getAsync('some_url').then(function(resp) {
   request.getAsync('some_other_url').then(..processing code..);
});
+3

All Articles