aws-sdk-js: Error: Non-file stream objects are not supported with SigV4 when using s3.uploadPart()

I get the following error:

Non-file stream objects are not supported with SigV4

when passing a FileStream to s3.uploadPart().

Oddly I don’t get the error if I swap s3.uploadPart() for s3.upload() - this leads me to believe my object is a valid file stream.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@PsyTae With version 2.4.0, the S3 client was updated to use Sigv4 by default. It’s still possible to use Sigv2 by specifying you want to use that when instantiating your client:

var s3 = new AWS.S3({signatureVersion: 'v2'})

This issue should only occur when using signatureVersion: v4 due to how the body is signed. Can you share how your input stream is created?

The stream is created by Busboy https://github.com/mscdex/busboy and I just pass it as is to s3

router.post('/upload/:key/:uploadId/:partNumber', function(req, res, next) {
  var busboy = new Busboy({
    headers: req.headers
  });

  busboy.on('file', (fieldname, stream, filename, encoding, mimetype) => {
      let s3req = s3.uploadPart({
        Bucket: process.env.AWS_BUCKET,
        Key: req.params.key,
        UploadId: req.params.uploadId,
        PartNumber: req.params.partNumber,
        Body: stream,
      });

      s3req.send((err, data) => {
        if (err) {
          return next(err);
        }

        res.send(data);
      });

  });

  req.pipe(busboy);
});

Note that if I build the incoming busboy stream in memory before handing it to s3.uploadPart() it works fine:

The stream is created by Busboy https://github.com/mscdex/busboy and I just pass it as is to s3 - but that’s just to slow and memory intensive.

router.post('/upload/:key/:uploadId/:partNumber', function(req, res, next) {
  var busboy = new Busboy({
    headers: req.headers
  });

  busboy.on('file', (fieldname, stream, filename, encoding, mimetype) => {
    stream.fileRead = [];
    stream.on('data', (chunk) => {
      stream.fileRead.push(chunk);
    });

    stream.on('end', () => {
      let s3req = s3.uploadPart({
        Bucket: process.env.AWS_BUCKET,
        Key: req.params.key,
        UploadId: req.params.uploadId,
        PartNumber: req.params.partNumber,
        Body: stream.fileRead,
      });

      s3req.send((err, data) => {
        if (err) {
          return next(err);
        }

        res.send(data);
      });
    });

  });

  req.pipe(busboy);
});