index.js
function s3streamer(s3, opts) {
  var headers = (opts || {}).headers || { }

  return function (file, filename, mimetype, encoding, callback) {
    headers['Content-Type'] = mimetype
    var buf = Buffer(0)
    file.on('data', function (chunk) {
      buf = Buffer.concat([buf, chunk])
    })
    file.on('end', function () {
      s3.putBuffer(buf, filename, headers, function (err, s3resp) {
        if (err) {
          return callback(err)
        } else if (s3resp.statusCode < 200 || s3resp.statusCode > 299) {
          return callback(new Error('Error uploading to s3: ' + s3resp.statusCode), s3resp)
        }
        s3resp.resume() // This finalizes the stream response
        callback()
      })
    })
  }
}
function s3streamer(s3, opts) {
  var headers = (opts || {}).headers || { }

  return function (file, filename, mimetype, encoding, callback) {
    headers['Content-Type'] = mimetype
    var buf = Buffer(0)
    file.on('data', function (chunk) {
      buf = Buffer.concat([buf, chunk])
    })
    file.on('end', function () {
      s3.putBuffer(buf, filename, headers, function (err, s3resp) {
        if (err) {
          return callback(err)
        } else if (s3resp.statusCode < 200 || s3resp.statusCode > 299) {
          return callback(new Error('Error uploading to s3: ' + s3resp.statusCode), s3resp)
        }
        s3resp.resume() // This finalizes the stream response
        callback()
      })
    })
  }
}
function s3streamer ( s3 , opts ) { var headers = ( opts || { } ) . headers || { } return function ( file , filename , mimetype , encoding , callback ) { headers [ 'Content-Type' ] = mimetype var buf = Buffer ( 0 ) file . on ( 'data' , function ( chunk ) { buf = Buffer . concat ( [ buf , chunk ] ) } ) file . on ( 'end' , function ( ) { s3 . putBuffer ( buf , filename , headers , function ( err , s3resp ) { if ( err ) { return callback ( err ) } else if ( s3resp . statusCode < 200 || s3resp . statusCode > 299 ) { return callback ( new Error ( 'Error uploading to s3: ' + s3resp . statusCode ) , s3resp ) } s3resp . resume ( ) // This finalizes the stream response callback ( ) } ) } ) } }
An s3 streamer
An s3 streamer