Stream File Directly to s3 using NodeJS+Express, aws-sdk Stream File Directly to s3 using NodeJS+Express, aws-sdk express express

Stream File Directly to s3 using NodeJS+Express, aws-sdk


Streaming is now supported (see docs), simply pass the stream as the Body:

var fs = require('fs');var someDataStream = fs.createReadStream('bigfile');var s3 = new AWS.S3({ params: { Bucket: 'myBucket', Key: 'myKey' } });s3.putObject({ Body: someDataStream, ... }, function(err, data) {  // handle response})


The s3.putObject() method does not stream, and from what I see, the s3 module doesn't support streaming. However, with Knox, you can use Client.putStream(). Using the file object from your question, you can do something like this:

var fs = require('fs');var knox = require('knox');var stream = fs.createReadStream('./file');var client = knox.createClient({  key: '<api-key-here>',  secret: '<secret-here>',  bucket: 'learnboost'});var headers = {  'Content-Length': file.size,  'Content-Type': file.type};client.putStream(stream, '/path.ext', headers, function(err, res) {  // error or successful upload});