From d6b89fe2efa9385b2c4fcb6de6e334584b414446 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Wed, 26 Jun 2013 14:43:53 -0700 Subject: [PATCH] Add an express demo for metadata apis, upload/download --- example/upload.js | 67 ++++++++++++++++++++++++++++++++ lib/storage-handler.js | 87 ++++++++++++++++++++++++++++++++++++++++++ package.json | 2 + 3 files changed, 156 insertions(+) create mode 100644 example/upload.js create mode 100644 lib/storage-handler.js diff --git a/example/upload.js b/example/upload.js new file mode 100644 index 0000000..ebc6699 --- /dev/null +++ b/example/upload.js @@ -0,0 +1,67 @@ +var Uploader = require('../lib/storage-handler.js'); + +var express = require('express'); +var app = express(); + +app.configure(function () { + app.set('port', process.env.PORT || 3000); + 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); +}); + +var handler = new Uploader({provider: 'filesystem', root: '/tmp/storage'}); + +app.get('/', function (req, res, next) { + res.setHeader('Content-Type', 'text/html'); + var form = "
" + + " File to upload:
" + + " Notes about the file:
" + + "
"; + res.send(form); + res.end(); +}); + +app.post('/upload/:container', function (req, res, next) { + handler.processUpload(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.client.getContainers(function (err, containers) { + var html = "

Containers