0

I want to re size a uploaded image on nodejs and send it on via ftp. Using nodejs, busboy, GraphicsMagick, and jsftp.

var uploadFile = function(dir, req, cb) {
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {

  var imageMagick = gm.subClass({
    imageMagick: true
  });

  console.log('Resizing file...');
  console.log(filename);

  imageMagick(file)
    .resize(150, 150)
    .stream(function(err, stdout, stderr) {
      if (err)
        console.log(err);

      var i = [];

      stdout.on('data', function(data) {
        console.log('data');
        i.push(data);
      });

      stdout.on('close', function() {
        console.log('close');

        var image = Buffer.concat(i);

        console.log(image.length);
        console.log(image);

        ftp.put(image, filepath, function(hadError) {
          if (!hadError) {
            filename = config.one.filepath + dir + "/" + filename;
            cb(null, filename);
          } else {
            console.log(hadError);
            cb(hadError, 'Error');
          }
        });
      });
    });
});
req.pipe(req.busboy);
};

The output is now:

Resizing file...
100-0001_IMG.JPG
close
0
<Buffer >

On ftp server side I get a 0 bytes file and also never doing a cb. I found this two questions but couln't make it work for me: Question 1 Question 2

I guess there must be something wrong with my file I gave to gm because "data" is never written to the console. File it self is fine since I managed to upload a unresized file to the ftp server.

I appreciate every help!

Thx

4
  • 1
    Did you try to add stdout.error event to see possible errors from imageMagick?
    – Rax Wunter
    Nov 23, 2015 at 15:59
  • Yes this helped a bit: "Unzul„ssiger Parameter - -resize" --> "invalid Parameter - -resize". but not sure how to solve it. Just doing: "imageMagick(file).stream(function(err, stdout, stderr) {" gives back: "Unzul„ssiger Parameter - -" @RaxWunter
    – PowPi
    Nov 23, 2015 at 16:49
  • 1
    So problem is with imageMagick. Check, maybe you have odd versions of installed imagemagick and node-imagemagick
    – Rax Wunter
    Nov 23, 2015 at 16:53
  • @RaxWunter! This solved it. Donwloaded and installed all the stuff again and it worked. Thx alot!
    – PowPi
    Nov 23, 2015 at 17:10

1 Answer 1

1

Firstly you can check your stream for errors:

stdout.on('error', function(err) {
    console.log(err);
});

So if there is an error related to imageMagick it can be a mismatching of imageMagic binary and node-imagemagick library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.