S3 file upload stream using node js
amazon-s3, file-upload, node.js
Solution
You can now use streaming with the official Amazon SDK for nodejs in the section "Uploading a File to an Amazon S3 Bucket" or see their example on GitHub.
What's even more awesome, you finally can do so without knowing the file size in advance. Simply pass the stream as the `Body`:
var fs = require('fs');
var zlib = require('zlib');
var body = fs.createReadStream('bigfile').pipe(zlib.createGzip());
var s3obj = new AWS.S3({params: {Bucket: 'myBucket', Key: 'myKey'}});
s3obj.upload({Body: body})
.on('httpUploadProgress', function(evt) { console.log(evt); })
.send(function(err, data) { console.log(err, data) });
Problem
I am trying to find some solution to stream file on amazon S3 using node js server with requirements: - Don't store temp file on server or in memory. But up-to some limit not complete file, buffering can be used for uploading. - No restriction on uploaded file size. - Don't freeze server till complete file upload because in case of heavy file upload other request's waiting time will unexpectedly increase. I don't want to use direct file upload from browser because S3 credentials needs to share in that case. One more reason to upload file from node js server is that some authentication may also needs to apply before uploading file. I tried to achieve this using node-multiparty. But it was not working as expecting. You can see my solution and issue at https://github.com/andrewrk/node-multiparty/issues/49. It works fine for small files but fails for file of size 15MB. Any solution or alternative ?