Skip to content

Instantly share code, notes, and snippets.

@BrentAureli
Created April 20, 2015 14:46
Show Gist options
  • Save BrentAureli/59e25d77e0631cb58153 to your computer and use it in GitHub Desktop.
Save BrentAureli/59e25d77e0631cb58153 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
S3FS = require('s3fs'),
s3fsImpl = new S3FS('mybucket-BrentsTest', {
accessKeyId: 'XXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXX'
});
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
// Create our bucket if it doesn't exist
s3fsImpl.create();
module.exports = function(router){
router.use(multipartyMiddleware);
router.post('/testupload', function (req, res) {
var file = req.files.file;
var stream = fs.createReadStream(file.path);
return s3fsImpl.writeFile(file.originalFilename, stream).then(function () {
fs.unlink(file.path, function (err) {
if (err) {
console.error(err);
res.send(err);
}
});
res.redirect('/profile');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment