Skip to content

Instantly share code, notes, and snippets.

@yanatan16
Created October 8, 2013 14:55
Show Gist options
  • Save yanatan16/6886035 to your computer and use it in GitHub Desktop.
Save yanatan16/6886035 to your computer and use it in GitHub Desktop.
Pipe uploads to S3 with node.js and express
var express = require('express')
, knox = require('knox')
var bucket = 'your-bucket'
, s3 = knox.createClient({
secure: true,
bucket: bucket,
key: your_key,
secret: your_secret
})
, app = express();
app.use(express.multipart({ defer: true }));
app.post('/upload', function (req, res) {
var headers = {
'x-amz-acl': 'public-read'
}
req.form.on('part', function (part) {
headers['Content-Length'] = part.byteCount;
s3.putStream(part, part.filename, headers, function (err, s3res) {
if (err) {
return res.send(500, err);
}
res.statusCode = s3res.statusCode;
s3res.pipe(res);
});
});
});
app.listen(8888)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment