How to use gm(graphicsmagick) or imagemagick with stream? NodeJS

713 views Asked by At

I don't know how to use it, even though I had research but it still not work

fs.rename(tmpFile, nFile, function(){
        var stream = fs.createReadStream(nFile);
        var req = knoxClient.putStream(stream, fName, {
          'Content-type': 'image/jpeg',
          'Content-Length': fSize
        }, function(err, results){
          console.log(results);
        });
        req.on('response', function(resX){
          if(resX.statusCode == 200){
            console.log("Pushed Success!!!!!!!!");
            res.writeHead(200, {'Content-type': 'text/plain'});
            res.end(JSON.stringify({"FileName": fName}));
          }else{
            var err = new Error("Error" + resX.statusCode);
            err.status = resX.statusCode;
            next(err);
          }
        });
});

Lastly, use gm(or im) before createReadStream or after ?

1

There are 1 answers

0
user305015 On

There is an example on knox documentation

fs.stat('./Readme.md', function(err, stat){
  // Be sure to handle `err`.

  var req = client.put('/Readme.md', {
      'Content-Length': stat.size
    , 'Content-Type': 'text/plain'
  });

  fs.createReadStream('./Readme.md').pipe(req);

  req.on('response', function(res){
    // ...
  });
});