Streaming Uploads/Downloads using Sails.js and PostgreSQL.
$ npm install skipper-postgresql --save
module.exports.skipper = {
adapter: require('skipper-postgresql'),
connection: {
host: 'localhost',
user: 'postgres',
password: 'postgres'
},
/**
* OR
*
connection: 'postgres://postgres:postgres@localhost:5432/postgres'
*/
/**
* table to store files in
*/
fileTable: 'file'
}
module.exports = {
upload: function (req, res) {
req.file('upload').upload(sails.config.skipper, function (err, files) {
if (err) return res.negotiate(err);
res.ok(files)
})
},
download: function (req, res) {
var SkipperAdapter = sails.config.skipper.adapter;
SkipperAdapter(sails.config.skipper).read(req.param('fd'), function (err, file) {
if (err) return res.negotiate(err);
res.send(new Buffer(file))
})
}
}
MIT