form-data: GraphicsMagick Steams Failing?

I am having trouble getting node-gm streams to be accepted by form-data, for example the following code:

gm('somefilepath.png')
  .resize(100, 100)
  .noProfile()
  .stream(function(err, stdout, stderr) {
    form = new FormData()
    form.append('file', stdout)
    form.submit('http://foo')
  })

fails with an error

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Parse Error
    at Socket.socketOnData (http.js:1367:20)
    at TCP.onread (net.js:403:27)

Note that file streams work no problem with form-data, but i just can’t get the GM stream. Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 44 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Just stumbled across this when I thought I was going to lose my mind. Probably not too helpful to you two at this point but if some weary traveller finds this thread, adding the filetype solved my issue:

.stream('png', function( err, stdout, stderr ) {

    var buf = new Buffer(0);

    stdout.on('data', function(data) {
        buf = Buffer.concat([buf, data]);
    });

    stdout.on('end', function() {

        var data = {
            Bucket: 'my-bucket-name',
            Key: imageFilename,
            Body: buf
        };

        s3.putObject(data, function( err, response ) {
            if ( err ) {
                console.log( err );
            } else {
                console.log( chalk.green('Image #' + iterator + ' successfully generated for ' + text ) );
                iterator++;
                setImmediate( generateImages );
            }
        });
    });