How i can pipe image file to upload endpoint with superagent?
Asked Answered
C

1

9
/**
 *  Request png
 */
 var request = require('superagent')
 var req = request.get('http://example.com/original/' + id + '.png');

 req.end(function(response){
   // Here i want send responsed image to another server
   req.post('http://upload-example.com').attach('???')
 })

How i can pipe image file to upload endpoint? I use latest version of superagent in nodejs env.

Contentious answered 16/7, 2014 at 5:21 Comment(0)
M
2

attach can set Buffer.
But, you need to use filename option.

this works well.

var request = require('superagent');
request.get('https://example.com/image.png')
  .end((err, res) => {
    // Here i want send responsed image to another server
    console.log(err, res.body); // body is Buffer
    request.post('http://upload-example.com')
      .attach('image', res.body, {filename: 'test.png'})
      .end((err, res) => {
        console.log(err, res.statusCode);
      });
});
Margie answered 5/4, 2016 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.