Created
October 8, 2013 14:55
-
-
Save yanatan16/6886035 to your computer and use it in GitHub Desktop.
Pipe uploads to S3 with node.js and express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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