如何使用gm(graphicsmagick)或imagemagick与流?的NodeJS

时间:2016-12-17 12:09:22

标签: node.js express imagemagick graphicsmagick knox-amazon-s3-client

我不知道如何使用它,即使我有研究但它仍然无效

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);
          }
        });
});

最后,在createReadStream之前或之后使用gm(或im)?

1 个答案:

答案 0 :(得分:0)

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){
    // ...
  });
});