Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/Node.js/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Sample code for Node.js

This sample is written for [Node.js 0.6+](http://nodejs.org/) and requires [Express](http://expressjs.com/) to make the sample code cleaner.
This sample is written for [Node.js](http://nodejs.org/) and requires [Express](http://expressjs.com/) to make the sample code cleaner.

To install and run:

cd samples/Node.js
npm install express
npm install
node app.js

Then browse to [localhost:3000](http://localhost:3000).
Expand Down
34 changes: 18 additions & 16 deletions samples/Node.js/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
process.env.TMPDIR = 'tmp'; // to avoid the EXDEV rename error, see http://stackoverflow.com/q/21071303/76173

var express = require('express');
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
var flow = require('./flow-node.js')('tmp/');
var flow = require('./flow-node.js')('tmp');
var app = express();

// Host most stuff in the public folder
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/../../src'));

// Handle uploads through Flow.js
app.post('/upload', multipartMiddleware, function(req, res){
flow.post(req, function(status, filename, original_filename, identifier){
console.log('POST', status, original_filename, identifier);
res.send(200, {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
app.post('/upload', multipartMiddleware, function(req, res) {
flow.post(req, function(status, filename, original_filename, identifier) {
console.log('POST', status, original_filename, identifier);
res.send(200, {
// NOTE: Uncomment this funciton to enable cross-domain request.
//'Access-Control-Allow-Origin': '*'
});
});
});
});

// Handle cross-domain requests
Expand All @@ -31,15 +33,15 @@ app.post('/upload', multipartMiddleware, function(req, res){
*/

// Handle status checks on chunks through Flow.js
app.get('/upload', function(req, res){
flow.get(req, function(status, filename, original_filename, identifier){
console.log('GET', status);
res.send(200, (status == 'found' ? 200 : 404));
});
app.get('/upload', function(req, res) {
flow.get(req, function(status, filename, original_filename, identifier) {
console.log('GET', status);
res.send(200, (status == 'found' ? 200 : 404));
});
});

app.get('/download/:identifier', function(req, res){
flow.write(req.params.identifier, res);
app.get('/download/:identifier', function(req, res) {
flow.write(req.params.identifier, res);
});

app.listen(3000);
app.listen(3000);
Loading