var StorageService = require('../').StorageService; var express = require('express'); var app = express(); app.configure(function () { app.set('port', process.env.PORT || 3001); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.use(express.favicon()); // app.use(express.logger('dev')); app.use(express.methodOverride()); app.use(app.router); }); // Create the container var mkdirp = require('mkdirp'); mkdirp.sync('/tmp/storage/con1'); var handler = new StorageService({provider: 'filesystem', root: '/tmp/storage'}); app.get('/', function (req, res, next) { res.setHeader('Content-Type', 'text/html'); var form = "

Storage Service Demo

" + "List all containers

" + "Upload to container con1:

" + "

" + "File to upload:
" + "Notes about the file:
" + "
" + ""; res.send(form); res.end(); }); app.post('/upload/:container', function (req, res, next) { handler.upload(req, res, function (err, result) { if (!err) { res.setHeader('Content-Type', 'application/json'); res.send(200, result); } else { res.send(500, err); } }); }); app.get('/download', function (req, res, next) { handler.getContainers(function (err, containers) { var html = "

Containers

Home

"; res.send(200, html); }); }); app.get('/download/:container', function (req, res, next) { handler.getFiles(req.params.container, function (err, files) { var html = "

Files in container " + req.params.container + "

Home

"; res.send(200, html); }); }); app.get('/download/:container/:file', function (req, res, next) { handler.download(req, res, function (err, result) { if (err) { res.send(500, err); } }); }); app.listen(app.get('port')); console.log('http://127.0.0.1:' + app.get('port'));