Created
April 20, 2015 14:46
-
-
Save BrentAureli/59e25d77e0631cb58153 to your computer and use it in GitHub Desktop.
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 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